Guido van Rossum added the comment:
This is a known limitation. To get this to work you have to pass globals() and
locals():
typing.get_type_hints(Test, globals(), locals())
--
nosy: +gvanrossum
resolution: -> wont fix
stage: -> resolved
status: open -> closed
New submission from Fabian.M :
The following code throws with "NameError: name 'Nested' is not defined".
For reference, it works well when moving class definitions out of the local
scope.
import typing
T = typing.TypeVar('T')
def test():
class Nested(typing.Generic[T]):
pass