Great. If you’d like to add something to the docs for get_type_hints()
about this behavior please submit a PR — I don’t see a reason this would
suddenly change but it’s better to make sure.
On Tue, Dec 8, 2020 at 22:29 Paul Bryan wrote:
> Rereading PEP 563, I'm clearly railing against it. I beli
Rereading PEP 563, I'm clearly railing against it. I believe I can work
with __annotations__ as you suggest assuming the contract going forward
is for get_type_hints to return annotations verbatim if they're not
strings or ForwardRefs (the current implementation).
Thank you and Gregory for your ti
On Tue, Dec 8, 2020 at 8:58 PM Paul Bryan wrote:
> My use case is to for type annotations to resolve type encoders, decoders
> and validators at runtime.
>
What is the reason you can't insist that the annotations be globals or at
least accessible from there (e.g. class attributes)? If the reason
Yep, your example, *boom*.
My use case is to for type annotations to resolve type encoders,
decoders and validators at runtime.
Without __future__, type annotations specified in closure scope are
correctly attached to class variables, function parameters and return
types. Because they're in scope
What is the utility of a type annotation when the thing it refers to cannot
exist?
Deferred annotation lookups are intended to be something that analysis time
can make sense of but can always have no useful meaning at runtime.
No nesting required:
```
from __future__ import annotations
Class X:
Let's try an example that static type checkers should have no problem
with:
Python 3.9.0 (default, Oct 7 2020, 23:09:01)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>>
>>> def make_a_class():
... class
Yeah, static type checkers won't like it regardless.
On Tue, Dec 8, 2020 at 6:39 PM Paul Bryan wrote:
> It appears that when from future import __annotations__, a type hint
> annotation derived from a closure loses scope.
>
> Simplistic example:
>
> Python 3.9.0 (default, Oct 7 2020, 23:09:01)