Unnecessary async/await (ARCH2025)
Ce contenu n’est pas encore disponible dans votre langue.
Key python.async.unnecessary-async-await · Severity info · Category async
An async function whose only await is on the single returned expression adds a state-machine and microtask hop with no benefit. Returning the coroutine directly yields the same result with less overhead.
Incorrect
Section titled “Incorrect”async def get_user(user_id): return await fetch_user(user_id) # the only await is the returnCorrect
Section titled “Correct”def get_user(user_id): return fetch_user(user_id) # return the coroutine directlyDrop the async/await pair and return the coroutine directly; the caller will await it.