You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mypy behaves unexpectedly when caller provides a list expression that has non-int items to a function that accepts Union[List[int], T]:
fromtypingimport*T=TypeVar('T')
deff(a: Union[List[int], T]) ->T: passf([1]) # OKf(['']) # E: List item 0 has incompatible type "str" <<--- unexpecteda= ['']
f(a) # OK
It would be better if mypy would always recognize that List[str] is a valid argument for f. However, if given a [] argument the inferred return type should be List[int].
Mypy behaves unexpectedly when caller provides a list expression that has non-int items to a function that accepts
Union[List[int], T]
:It would be better if mypy would always recognize that
List[str]
is a valid argument forf
. However, if given a[]
argument the inferred return type should beList[int]
.This was originally discussed at #3501 (comment).
The text was updated successfully, but these errors were encountered: