[issue42829] get_type_hints throws for nested class with __future__ annotations

Svyatoslav report at bugs.python.org
Tue Jan 5 06:40:50 EST 2021


Svyatoslav <prometheus3375 at gmail.com> added the comment:

>
This is because get_type_hints looks only at mro of the class. Its namespace must be included too as locals
<

I'll correct myself. get_type_hints() looks at all entites of mro of a class. If globals are not defined, globals of an entity module are used. But if locals are not defined, then no action is taken. Actually, class namespace must be used as locals in that case.

This is also supported by the case when a class and its module have classes with the same name. See same_classes.py for an example.

----------
Added file: https://bugs.python.org/file49720/same_classes.py

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


More information about the Python-bugs-list mailing list