Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type overloads for async sleep function #399

Closed
Zac-HD opened this issue Apr 14, 2023 · 0 comments · Fixed by #400
Closed

Add type overloads for async sleep function #399

Zac-HD opened this issue Apr 14, 2023 · 0 comments · Fixed by #400

Comments

@Zac-HD
Copy link

Zac-HD commented Apr 14, 2023

import trio  # or asyncio, etc.
import tenacity

@tenacity.retry(
    sleep=trio.sleep,  # typecheckers will error here!
)
async def foo():
    pass

The type annotation here

@t.overload
def retry(
sleep: t.Callable[[t.Union[int, float]], None] = sleep,

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!

jakkdl added a commit to jakkdl/tenacity that referenced this issue Apr 18, 2023
jakkdl added a commit to jakkdl/tenacity that referenced this issue Apr 18, 2023
@mergify mergify bot closed this as completed in #400 Aug 14, 2023
clrpackages pushed a commit to clearlinux-pkgs/pypi-tenacity that referenced this issue Aug 15, 2023
…sion 8.2.3

Felix Yan (1):
      Fix tests for typeguard 3.x (#394)

John Litborn (1):
      Add support for async sleep functions in tenacity.retry annotation. Fixes jd/tenacity#399 (#400)

Julien Danjou (1):
      chore: remove support for Python 3.6

Kushal Gajurel (1):
      Added the link to documentation for a better experience (#409)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant