Title: typing.get_type_hints wrong namespace for forward-declaration of inner class
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: levkivskyi, netbnd
Priority: normal Keywords:

Created on 2019-08-13 09:36 by netbnd, last changed 2019-08-16 19:12 by levkivskyi.

File name Uploaded Description Edit netbnd, 2019-08-13 09:36 A simple file to reproduce the error with inner classes.
Messages (1)
msg349535 - (view) Author: Netzeband (netbnd) Date: 2019-08-13 09:36
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.
Date User Action Args
2019-08-16 19:12:54levkivskyisetnosy: + levkivskyi
2019-08-13 09:36:43netbndcreate