<div dir="ltr"><div dir="ltr"><div>On Sat, Sep 22, 2018 at 3:11 PM Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote: </div><div>> 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.</div><div><br></div><div>On Sat, Sep 22, 2018 at 4:38 PM Yury Selivanov <<a href="mailto:yselivanov.ml@gmail.com">yselivanov.ml@gmail.com</a>> wrote:</div><div>> If it's possible to fix exec() to accept any Mapping (not just dicts),</div><div>> then we can create a proxy mapping for "Dataclass.__init__.__module__"</div><div>> module and everything would work as expected.  </div><div><br></div><div>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.</div></div></div>