On Sat, Sep 22, 2018 at 3:11 PM Guido van Rossum <gu...@python.org> wrote: > Still, I wonder if there's a tweak possible of the globals and locals used when exec()'ing the function definitions in dataclasses.py, so that get_type_hints() gets the right globals for this use case.
On Sat, Sep 22, 2018 at 4:38 PM Yury Selivanov <yselivanov...@gmail.com> wrote: > If it's possible to fix exec() to accept any Mapping (not just dicts), > then we can create a proxy mapping for "Dataclass.__init__.__module__" > module and everything would work as expected. Another possible solution is that `__annotations__` are *permitted* to be lambdas, but not created as such by default, and `get_type_hints` is aware of this. Operations that are known to break type hints (such as when data classes copy the type hints from the class body to the `__init__` method) could covert the type hint from a string to a lambda before moving it. It does not even have to be a lambda; an instance of some `TypeHint` class, which stores the string and pointers to the original `globals` and `locals` (or just the original object whose `globals` and `locals` are relevant), but that's essentially what a lambda is anyway.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com