Add type overloads for async `sleep` function
Zac-HD opened this issue · comments
Zac Hatfield-Dodds commented
import trio # or asyncio, etc.
import tenacity
@tenacity.retry(
sleep=trio.sleep, # typecheckers will error here!
)
async def foo():
pass
The type annotation here
Lines 500 to 502 in 4333249
should be
t.Callable[[t.Union[int, float]], t.Union[None, t.Awaitable[None]]
, since AsyncRetrying
allows async sleep
functions.
Going further, we could define an additional AsyncWrappedFn
typevar and propagate that though to ensure that the sleep
callback is always awaitable when retrying for a coroutine function. This is a pretty important performance footgun to avoid!