The discussion around PEP 649 got me thinking about what I believe is the
largest downside to PEP 563: the inability to evaluate annotations created
with closures.  While this is in general unavoidable,  if the type is ever
referenced in an annotated function (including as an annotation) it should
be resolvable via `__closure__`.

For example:
```
from __future__ import annotations
import typing
def gen(T):
    def f(x: T):
        y: T = ...
    return f

f = gen(int)
nonlocal_vars = {
  var : cell.cell_contents
  for var, cell in zip(f.__code__.co_freevars, f.__closure__)
}
assert typing.get_type_hints(f, localns=nonlocal_vars)  == {'x': int}
```

I would just open a PR to have `get_type_hints` attempt to resolve closure
variables by default.  However, this would require an update to PEP 563 and
I don't know what the protocol is there.

-  Caleb Donovick
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/L2XH2EIFCEPT5DQRPRFR6WYEM6M2LM2V/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to