Re: [Python-Dev] Postponed annotations break inspection of dataclasses

2018-09-22 Thread Yury Selivanov
On Sat, Sep 22, 2018 at 3:11 PM Guido van Rossum 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 > get_type_hints() gets the right globals for this use case. > > It's really tough to

Re: [Python-Dev] Postponed annotations break inspection of dataclasses

2018-09-22 Thread Guido van Rossum
On Sat, Sep 22, 2018 at 11:29 AM Eric V. Smith 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: > >

Re: [Python-Dev] Postponed annotations break inspection of dataclasses

2018-09-22 Thread Eric V. Smith
On 9/22/2018 12:41 PM, Guido van Rossum wrote: This is a good catch -- thanks for bringing it up. I'm adding Eric Smith (author of dataclasses) and Ivan Levkivskyi (co-author of typing) as well as Łukasz Langa (author of PEP 563) to the thread to see if they have further insights. I don't

Re: [Python-Dev] Postponed annotations break inspection of dataclasses

2018-09-22 Thread Guido van Rossum
This is a good catch -- thanks for bringing it up. I'm adding Eric Smith (author of dataclasses) and Ivan Levkivskyi (co-author of typing) as well as Łukasz Langa (author of PEP 563) to the thread to see if they have further insights. Personally I don't think it's feasible to change PEP 563 to

[Python-Dev] Postponed annotations break inspection of dataclasses

2018-09-22 Thread David Hagen
The new postponed annotations have an unexpected interaction with dataclasses. Namely, you cannot get the type hints of any of the data classes methods. For example, I have some code that inspects the type parameters of a class's `__init__` method. (The real use case is to provide a default