[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Postponed annotations break inspection of dataclasses

On Sat, Sep 22, 2018 at 11:29 AM Eric V. Smith <eric at> 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, 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 (
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>