bpo-37838: get_type_hints for wrapped functions with forward reference#17126
bpo-37838: get_type_hints for wrapped functions with forward reference#17126ilevkivskyi merged 5 commits intopython:masterfrom
Conversation
brandtbucher
left a comment
There was a problem hiding this comment.
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) No newline at end of file |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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 <brandtbucher@gmail.com>
|
(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 <53377856+benedwards14@users.noreply.github.com>
pythonGH-17126) https://bugs.python.org/issue37838 (cherry picked from commit 0aca3a3) Co-authored-by: benedwards14 <53377856+benedwards14@users.noreply.github.com>
GH-17126) https://bugs.python.org/issue37838 (cherry picked from commit 0aca3a3) Co-authored-by: benedwards14 <53377856+benedwards14@users.noreply.github.com>
GH-17126) https://bugs.python.org/issue37838 (cherry picked from commit 0aca3a3) Co-authored-by: benedwards14 <53377856+benedwards14@users.noreply.github.com>
https://bugs.python.org/issue37838