-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-37838: get_type_hints for wrapped functions with forward reference #17126
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
bpo-37838: get_type_hints for wrapped functions with forward reference #17126
Conversation
brandtbucher
left a comment
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.
This looks like a good change to me! Just a few comments below to fix CI and clean things up.
Lib/test/ann_module.py
Outdated
| def dec(func): | ||
| def wrapper(*args, **kwargs): | ||
| return func(*args, **kwargs) | ||
| return wraps(func)(wrapper) |
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.
I think the tests are failing because of this missing newline:
| return wraps(func)(wrapper) | |
| return wraps(func)(wrapper) | |
Lib/test/test_typing.py
Outdated
|
|
||
| class ForRefExample(): | ||
| @ann_module.dec | ||
| def func(a: 'ForRefExample'): |
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.
Minor, but maybe just name this argument self for cleanliness?
| def func(a: 'ForRefExample'): | |
| def func(self: 'ForRefExample'): |
Lib/test/test_typing.py
Outdated
|
|
||
| @ann_module.dec | ||
| @ann_module.dec | ||
| def nested(a: 'ForRefExample'): |
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.
See above:
| def nested(a: 'ForRefExample'): | |
| def nested(self: 'ForRefExample'): |
Lib/test/test_typing.py
Outdated
| self.assertEqual(gth(G), {'lst': ClassVar[List[T]]}) | ||
|
|
||
| def test_get_type_hints_wrapped_decoratored_func(self): | ||
| expects = {'a': ForRefExample} |
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.
See above:
| expects = {'a': ForRefExample} | |
| expects = {'self': ForRefExample} |
|
Thanks for the PR @benedwards14! This one should also have a NEWS entry. Just something simple, like: :meth:`typing.get_type_hints` properly handles functions decorated with :meth:`functors.wraps`. |
|
Hey @brandtbucher, thanks for the review. Here are the markups. |
brandtbucher
left a comment
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.
Looks good! Just a couple of remaining style nitpicks:
Lib/test/test_typing.py
Outdated
|
|
||
| gth = get_type_hints | ||
|
|
||
| class ForRefExample(): |
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.
No parentheses here, and 2 blank lines between top-level definitions:
| class ForRefExample(): | |
| class ForRefExample: |
brandtbucher
left a comment
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.
Sorry, one last typo I spotted. Then good!
Misc/NEWS.d/next/Library/2019-11-21-11-39-17.bpo-37838.lRFcEC.rst
Outdated
Show resolved
Hide resolved
Co-Authored-By: Brandt Bucher <[email protected]>
ilevkivskyi
left a comment
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.
Looks good, thanks!
|
(Added backport labels since this is a bugfix.) |
|
Thanks @benedwards14 for the PR, and @ilevkivskyi for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8. |
|
GH-17324 is a backport of this pull request to the 3.8 branch. |
|
GH-17325 is a backport of this pull request to the 3.7 branch. |
pythonGH-17126) https://bugs.python.org/issue37838 (cherry picked from commit 0aca3a3) Co-authored-by: benedwards14 <[email protected]>
pythonGH-17126) https://bugs.python.org/issue37838 (cherry picked from commit 0aca3a3) Co-authored-by: benedwards14 <[email protected]>
GH-17126) https://bugs.python.org/issue37838 (cherry picked from commit 0aca3a3) Co-authored-by: benedwards14 <[email protected]>
GH-17126) https://bugs.python.org/issue37838 (cherry picked from commit 0aca3a3) Co-authored-by: benedwards14 <[email protected]>
https://bugs.python.org/issue37838