This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author netbnd
Recipients levkivskyi, netbnd
Date 2019-08-25.18:02:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I think I found a better workaround (by accident).

I was debugging another issue with get_type_hints for the case that this function is used inside the __new__ method of a metaclass and with methods of the class to define. Here the same issue happens: Forward declared type names are not inside the namespace of the function.

However, inside the __new__ method of the metaclass, you already know the name of the class you want to define and you know the class-object to define. With this information it is very easy to add the missing reference to the __globals__ list of all methods found in the namespace. 

So the workaround is to use a metaclass, which adds the class-name and class-object to the global namespace of the methods of this class. It works also in case of classes, which are inherited, from a class, which uses this metaclass.

This leads also to a non-workaround solution: Why is the own class not always inside the __globals__ list of the methods? Is there a reason? Or is this just a missing feature of the python-core?

What are you thinking about this solution? Do you see any issues or corner-cases with that?

Working code is attached to this ticket (
Date User Action Args
2019-08-25 18:02:32netbndsetrecipients: + netbnd, levkivskyi
2019-08-25 18:02:32netbndsetmessageid: <>
2019-08-25 18:02:32netbndlinkissue37835 messages
2019-08-25 18:02:32netbndcreate