Closed
Description
This code:
def f(x: Union[int, str, List, Tuple]) -> None:
if isinstance(x, (str, (int, tuple))):
print(x[1])
results in error: Argument 2 to "isinstance" has incompatible type "Tuple[str, Tuple[List[_T], Tuple[_T_co, ...]]]"; expected "Union[type, Tuple[type, ...]]".
Python 2 and 3 allow to put nested tuples as the second argument to isinstance, but neither typeshed nor mypy are aware of it. The typeshed needs to be fixed first (python/typeshed#997), but then still some logic needs to be updated inside mypy (otherwise, it results in internal error since it doesn't expect nested tuples; it should instead result in an type validation error).
Metadata
Metadata
Assignees
Labels
No labels