On 16 Apr 2021, at 16:59, Guido van Rossum wrote:
If you look deeper, the real complaints are all about the backwards
incompatibility when it comes to locally-scoped types in annotations. I.e.
def test():
class C: ...
def func(arg: C): ...
return func
typing.get_type_hints(test()) # raises NameError: name 'C' is not definedCan't this be solved by wrapping the annotation in a lambda, i.e.
>>> def test(): ... class C: ... ... def func(arg: lambda: C): ... ... return func ... >>> test().__annotations__['arg']() <class '__main__.test.<locals>.C'>
So
typing.get_type_hints()
would simply call an annotation if the annotation was callable and replace it with the result of the call.