Repository navigation
typing.get_type_hints fails when passed a class with PEP 695 type parameters and PEP 563 is enabled #114053
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jan 14, 2024 - added3.12only security fixesonly security fixes3.13only security fixesonly security fixes
on Jan 14, 2024 - changed the title
[-]typing.get_type_hints fails when passed a class with PEP 695 type parameters and PEP 563 is enabled[/-][+]typing.get_type_hints fails when passed a generic class and PEP 563 is enabled[/+]on Jan 14, 2024 - changed the title
[-]typing.get_type_hints fails when passed a generic class and PEP 563 is enabled[/-][+]typing.get_type_hints fails when passed a class with PEP 695 type parameters and PEP 563 is enabled[/+]on Jan 15, 2024 Sorry, my now-hidden comment above is incorrect - it does work fine with pre-695 generic classes, I just had a typo in the code.
This is only an issue with PEP 695 type parameters in conjunction with PEP 563.
+1, just ran into this as well.
I suppose the problem is probably that
get_type_hintslooks things up in the global scope but doesn't look things up in the new annotation scopes introduced by PEP-695. The old way of defining TypeVars doesn't suffer from this because TypeVars were defined in the global scope; now they aren't.- added 4 commits that reference this issue
on Apr 17, 2024 9 remaining items
- added a commit that references this issue
on Jun 25, 2024
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
This fails with a NameError:
Although
get_type_hintsdoes not work with imported imported type aliases, this is not imported, so I would expect it to work. Further, the documentation for the function indicates using PEP 563 should /help/, but in this case it actually causes an error.FWIW, removing the PEP 563 import works fine, giving:
Python version:
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
get_type_hints#118009get_type_hints(#118009) #118104inspect.get_annotations#120270get_type_hints, PEP 695 and PEP 563 #120272inspect.get_annotations(GH-120270) #120474inspect.get_annotations(GH-120270) #120475get_type_hints, PEP 695 and PEP 563 (GH-120272) #121003get_type_hints, PEP 695 and PEP 563 (GH-120272) #121004