-
Notifications
You must be signed in to change notification settings - Fork 4
Fix type hinting #5
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
Fix type hinting #5
Conversation
The test failures here will be fixed once #7 is merged and I've rebased this on top of that PR. |
Codecov Report
@@ Coverage Diff @@
## master #5 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 39 45 +6
=========================================
+ Hits 39 45 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Right, so the tests should now pass, because the mypy typechecks are skipped on anything other than 3.10. That's because mypy refuses to acknowledge the backported ParamSpec object for now on anything other than 3.10; I think python/mypy#12011 may be related there. This is a mypy bug, so I'm not taking the hints out again. :-) |
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 for the PR!
I have left some comments and there is a conflict, after you have fixed those then this is ready to go in.
Bah, humbug. I'll have to fix the PR push. I was trying to do this via GitHub codespaces on a mobile phone as I am travelling. |
- Use a `ParamSpec` to capture the wrapped function arguments and a separate `TypeVar` for the return type, so that the annotation can accurately wrap just the return value in a `Coroutine` annotation. - Add explicit type hints for functions that use @overload (which are not compatible with ParamSpec). - Add typing-extensions as a dependency (used for ParamSpec on older Python versions) - Add a few simple tests to verify that type hints now are producing correct output.
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.
LGTM Thanks!
This PR fixes the type hinting issue #4.
ParamSpec
to capture the wrapped function arguments and aseparate
TypeVar
for the return type, so that the annotation canaccurately wrap just the return value in a
Coroutine
annotation.are not compatible with ParamSpec).
Python versions)
correct output.
Note that I switched to using
Coroutine[Any, Any, ...]
here, it's the moreaccurate type hint.