[New-bugs-announce] [issue42824] get_type_hints throws for local class reference

Fabian.M report at bugs.python.org
Mon Jan 4 11:55:18 EST 2021

New submission from Fabian.M <f.mehmke at gmail.com>:

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]):

    class Test(typing.Generic[T]):
      nested: Nested[T]

    typing.get_type_hints(Test) # this throws


components: Library (Lib)
messages: 384332
nosy: Fabian.M
priority: normal
severity: normal
status: open
title: get_type_hints throws for local class reference
type: behavior
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list