Netzeband <an...@netzeband.eu> added the comment:

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 (metaclass_workaround.py)

----------
Added file: https://bugs.python.org/file48562/metaclass_workaround.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37835>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to