Message350468
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) |
|
Date |
User |
Action |
Args |
2019-08-25 18:02:32 | netbnd | set | recipients:
+ netbnd, levkivskyi |
2019-08-25 18:02:32 | netbnd | set | messageid: <1566756152.9.0.312994677565.issue37835@roundup.psfhosted.org> |
2019-08-25 18:02:32 | netbnd | link | issue37835 messages |
2019-08-25 18:02:32 | netbnd | create | |
|