[New-bugs-announce] [issue37835] typing.get_type_hints wrong namespace for forward-declaration of inner class

Netzeband report at bugs.python.org
Tue Aug 13 05:36:43 EDT 2019


New submission from Netzeband <andre at netzeband.eu>:

When evaluating the type-hints of an inner-class (a class defined inside a function scope), the forward declaration does not work correctly. In this case the typing.get_type_hints does not get the right namespace, thus the class-string specified is not found.

When using the same syntax for a normal class (defined in global space) it works, or when using another class instead a forward declaration, also everything works.

As a workaround one could pass the local namespace (locals()) from the function where the class has been defined in to typing.get_type_hints. However in normal situations the typing.get_type_hints call is deep in the call hierarchy to do some runtime type-checks and at this point only the reference to the function-object is existing and no-one is aware of the fact, that this is just a method defined in a inner class.

>From the outside perspective one would expect, that typing.get_type_hints reacts the same, independent of the type of class.

----------
components: Library (Lib)
files: typing_check.py
messages: 349535
nosy: netbnd
priority: normal
severity: normal
status: open
title: typing.get_type_hints wrong namespace for forward-declaration of inner class
type: behavior
versions: Python 3.6, Python 3.7
Added file: https://bugs.python.org/file48539/typing_check.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37835>
_______________________________________


More information about the New-bugs-announce mailing list