-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix decorator in retry module #5482
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good to me.
For the record, I think this might be a bug in mypy, since:
diff --git a/stubs/retry/retry/api.pyi b/stubs/retry/retry/api.pyi
index 88f274b9..6e1a0edd 100644
--- a/stubs/retry/retry/api.pyi
+++ b/stubs/retry/retry/api.pyi
@@ -25,4 +25,4 @@ def retry(
backoff: float = ...,
jitter: Union[Tuple[float, float], float] = ...,
logger: Optional[Logger] = ...,
-) -> _Decorator[_T]: ...
+) -> Callable[[_T], _T]: ...
is also enough to fix.
However, IIRC this shorthand where the TypeVar only occurs in the return type is sort of contentious syntax between type checkers, so using the callback protocol is probably for the best.
I extracted |
Thanks for having a look @hauntsaninja . |
Whatever you prefer, I can do it, or you can wait. |
Finish your work on 5483, I'll take care of retry later. |
#5483 is merged now. |
Merged master and updated to use IdentifyFunction. |
Thanks @srittau & @hauntsaninja ! |
Hi,
I'm afraid the type annotations for the retry module are incorrect, although it's possible that the real issue is in mypy; it's possible I don't understand typing annotations enough to be 100% sure.
I want to typecheck the following program with mypy:
Running with python3.7 (as provided by Debian) or 3.9.4 (latest version compiled locally) with mypy 0.820 and types-retry 0.1.1, I get the following:
Which is not right.
With the changes included in this PR, I get the expected errors from mypy:
I copied the definition of
_Decorator
fromstubs/click/click/decorators.pyi
.