On Fri, Nov 26, 2021 at 12:15:10AM +0900, Stephen J. Turnbull wrote: > I will grant that restricting the type of compiled annotations from > typing.Any to "string serializing an object's AST" could reasonably be > said to be "going out of your way to break other use cases". You have > a valid beef here, although it's not obvious to me how it should be > resolved.
I don't think that's what PEP 563 says. Annotations are not *restricted* to only be strings, it is merely that when the function or class object is built, the annotations are left as strings. So we can post-process annotations and destringify them: >>> from __future__ import annotations >>> def func(arg:float) -> int: ... pass ... >>> func.__annotations__ {'arg': 'float', 'return': 'int'} >>> func.__annotations__['return'] = int >>> func.__annotations__['arg'] = float >>> func.__annotations__ {'arg': <class 'float'>, 'return': <class 'int'>} There may be scoping issues to be sorted out, but I don't think they are insurmountable. -- Steven _______________________________________________ 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/24PKPJTI5SIES32C2KZVF6R6D3RLF6BI/ Code of Conduct: http://python.org/psf/codeofconduct/