-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
This may just be my misunderstanding, but it seems potentially undesirable, so I am reporting it as a bug. As of mypy 0.511, this typechecks just fine:
from typing import TypeVar, Tuple
V = TypeVar('V', bound=int)
E = Tuple[V, V]
def outgoing(edge: E) -> V: # Note unparameterized E
reveal_type(edge) # Revealed type is 'Tuple[Any, Any]'
return edge[1]
print(outgoing((1, 'a')))
It looks like declaring a variable of type E
ought to be the same as declaring it of type Tuple[V, V]
, but in fact it becomes Tuple[Any, Any]
. The issue is that the alias itself requires a type parameter (E[V]
). This is a mistake that is both easy to make and silently removes type safety. Unfortunately, the PEP and docs are not very clear about aliases needing parameters.
I'm not sure if there is a use case for missing alias parameters defaulting to Any
, but it seems like type safety would be greatly improved it produced a typechecking error instead. It would really be convenient if mypy could try to bind missing type alias parameters to bound parameters of the same name, which would improve both usability and type safety. Thanks!