[Python-Dev] Postponed annotations break inspection of dataclasses (original) (raw)
Raymond Hettinger raymond.hettinger at gmail.com
Mon Sep 24 02:23:47 EDT 2018
- Previous message (by thread): [Python-Dev] Postponed annotations break inspection of dataclasses
- Next message (by thread): [Python-Dev] Postponed annotations break inspection of dataclasses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sep 22, 2018, at 1:38 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
On Sat, Sep 22, 2018 at 3:11 PM Guido van Rossum <guido at 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 gettypehints() gets the right globals for this use case.
It's really tough to be at the intersection of three PEPs... 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
FWIW, the locals() dict for exec() already accepts any mapping (not just dicts):
>>> class M:
def __getitem__(self, key):
return key.upper()
def __setitem__(self, key, value):
print(f'{key!r}: {value!r}')
>>> exec('a=b', globals(), M())
'a': 'B'
Raymond
- Previous message (by thread): [Python-Dev] Postponed annotations break inspection of dataclasses
- Next message (by thread): [Python-Dev] Postponed annotations break inspection of dataclasses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]