$ poetry run python3 pep_695_get_type_hints.py
Traceback (most recent call last):
File "/home/mjog/pep_695_get_type_hints.py", line 8, in <module>
print(typing.get_type_hints(Test))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/typing.py", line 2197, in get_type_hints
value = _eval_type(value, base_globals, base_locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/typing.py", line 393, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/typing.py", line 900, in _evaluate
eval(self.__forward_code__, globalns, localns),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1, in <module>
NameError: name 'M' is not defined
$ poetry run python3 --version
Python 3.12.0
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