
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