On Sat, Sep 22, 2018 at 11:29 AM Eric V. Smith <e...@trueblade.com> wrote:

> I think this problem is endemic to get_type_hints(). I've never
> understood how you're supposed to use the globals and locals arguments
> to it, but this works:
>
> print(get_type_hints(Bar.__init__, globals()))
>
> as does:
>
> print(get_type_hints(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 get_type_hints 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)
_______________________________________________
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

Reply via email to