Join GitHub today
Allow subscripted aliases at function scope #4000
This PR allows subscripted type aliases at function scope, as discussed in #3145 this will simplify the rules and have other pluses (apart from fixing the actual issue).
In addition, I prohibit reuse of bound type variables to define generic aliases, situations like this were always ambiguous:
T = TypeVar('T') class C(Generic[T]): A = List[T] x: A reveal_type(x) # on one hand one might expect this to be List[T], # but on the other hand, non-subscripted generic aliases # get variables replaced with 'Any', so this should be 'List[Any]'.
Also prohibiting this use is consistent with how we prohibit bound type variable reuse for nested classes, one can always just use another type variable, so this works:
T = TypeVar('T') S = TypeVar('S') class C(Generic[T]): A = List[S] x: A[T]
Thanks for the PR! Looks pretty good, but I was confused in a few places.