[Python-Dev] Postponed annotations break inspection of dataclasses (original) (raw)
Guido van Rossum guido at python.org
Sat Sep 22 15:09:22 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 Sat, Sep 22, 2018 at 11:29 AM Eric V. Smith <eric at trueblade.com> wrote:
I think this problem is endemic to gettypehints(). I've never understood how you're supposed to use the globals and locals arguments to it, but this works:
print(gettypehints(Bar.init, globals())) as does: print(gettypehints(Bar.init, Bar.module)) But that seems like you'd have to know a lot about how a class were declared in order to call gettypehints on it. I'm not sure module is always correct (but again, I haven't really thought about it).
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.
It's really tough to be at the intersection of three PEPs...
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180922/ae1c4611/attachment.html>
- 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 ]