8000 bpo-45166: fixes `get_type_hints` failure on `Final` by sobolevn · Pull Request #28279 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div hidden="hidden" data-view-component="true" class="js-stale-session-flash stale-session-flash flash flash-warn flash-full"> Dismiss alert

bpo-45166: fixes get_type_hints failure on Final #28279

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

Merged
merged 8 commits into from
Sep 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Lib/typing.py
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
sobolevn and ambv authored Sep 24, 2021
commit ff0deb501fe5b16ee1a04f46cfbd00be022a61f8
8 changes: 4 additions & 4 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ def _type_check(arg, msg, is_argument=True, module=None, *, is_class=False):
We append the repr() of the actual value (truncated to 100 chars).
"""
invalid_generic_forms = (Generic, Protocol)
if is_argument and not is_class:
invalid_generic_forms = invalid_generic_forms + (ClassVar, Final)
elif not is_argument and not is_class: # module / local level
invalid_generic_forms = invalid_generic_forms + (ClassVar, )
if not is_class:
invalid_generic_forms += (ClassVar,)
if is_argument:
invalid_generic_forms += (Final,)
Comment on lines +167 to +170
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: there's a subtle change in the logic compared to the old code, but it's ok because is_argument defaulted to True in both ForwardRef and _type_check. Which means by default we should always add ClassVar too.


arg = _type_convert(arg, module=module)
if (isinstance(arg, _GenericAlias) and
Expand Down
0