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
When using overload, I realized that it wrongly does not complain about type mismatches as soon as one defines overloaded versions with Tuple of different arites. Here comes a minimal example:
from typing import Tuple, TypeVar, overload, List, Any
T = TypeVar('T')
_1 = TypeVar('_1')
_2 = TypeVar('_2')
_3 = TypeVar('_3')
@overload
def foo(bar: List[T], baz: List[T]) -> List[T]:
pass
@overload
def foo(bar: Tuple[_1, _2], baz: Tuple[_1, _2]) -> Tuple[_1, _2]:
pass
@overload
def foo(bar: Tuple[_1, _2, _3], baz: Tuple[_1, _2, _3]) -> Tuple[_1, _3]:
pass
def foo(bar: Any, baz: Any) -> Any:
return (bar[0], baz[-1])
# good call to foo
d: Tuple[int, str] = foo((1, 'a'), (2, 'a'))
# should fails, but currently only fails if Tuple[_1, _2, _3] overload is removed
e: Tuple[int, str] = foo((1, 'a'), (2, 3))
mypy 0.610
Python 3.6.5
The text was updated successfully, but these errors were encountered:
When using
overload
, I realized that it wrongly does not complain about type mismatches as soon as one defines overloaded versions with Tuple of different arites. Here comes a minimal example:The text was updated successfully, but these errors were encountered: