diff --git a/mypy/main.py b/mypy/main.py index a4357dca7890..3eb8a76a6de3 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -1359,7 +1359,7 @@ def set_strict_flags() -> None: parser.error("Can only find occurrences of class members.") if len(_find_occurrences) != 2: parser.error("Can only find occurrences of non-nested class members.") - state.find_occurrences = _find_occurrences # type: ignore[assignment] + state.find_occurrences = _find_occurrences # Set reports. for flag, val in vars(special_opts).items(): diff --git a/mypy/subtypes.py b/mypy/subtypes.py index 58ae4efdf582..409481953a5b 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -435,8 +435,10 @@ def visit_instance(self, left: Instance) -> bool: # dynamic base classes correctly, see #5456. return not isinstance(self.right, NoneType) right = self.right - if isinstance(right, TupleType) and right.partial_fallback.type.is_enum: - return self._is_subtype(left, mypy.typeops.tuple_fallback(right)) + if isinstance(right, TupleType): + return self._is_subtype(left, right.partial_fallback) and self._is_subtype( + left, mypy.typeops.tuple_fallback(right) + ) if isinstance(right, Instance): if type_state.is_cached_subtype_check(self._subtype_kind, left, right): return True diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index 0e7c81edc498..88e8a74833dc 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -113,7 +113,7 @@ t1: Tuple[A, A] t2: tuple if int(): - t1 = t2 # E: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "Tuple[A, A]") + t1 = t2 if int(): t2 = t1 @@ -1522,3 +1522,19 @@ class Bar(aaaaaaaaaa): # E: Name "aaaaaaaaaa" is not defined class FooBarTuple(Tuple[Foo, Bar]): ... [builtins fixtures/tuple.pyi] + +[case testTupleOverloadZipAny] +from typing import Any, Iterable, Iterator, Tuple, TypeVar, overload + +T = TypeVar("T") + +@overload +def zip(__i: Iterable[T]) -> Iterator[Tuple[T]]: ... +@overload +def zip(*i: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... +def zip(i): ... + +def g(t: Tuple): + reveal_type(zip(*t)) # N: Revealed type is "typing.Iterator[builtins.tuple[Any, ...]]" + reveal_type(zip(t)) # N: Revealed type is "typing.Iterator[Tuple[Any]]" +[builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-typevar-tuple.test b/test-data/unit/check-typevar-tuple.test index 2b47ff30cdfb..36fb88e389d4 100644 --- a/test-data/unit/check-typevar-tuple.test +++ b/test-data/unit/check-typevar-tuple.test @@ -60,9 +60,7 @@ reveal_type(f(f_args3)) # N: Revealed type is "Tuple[builtins.str, builtins.str f(empty) # E: Argument 1 to "f" has incompatible type "Tuple[()]"; expected "Tuple[int]" f(bad_args) # E: Argument 1 to "f" has incompatible type "Tuple[str, str]"; expected "Tuple[int, str]" -# The reason for error in subtle: actual can be empty, formal cannot. -reveal_type(f(var_len_tuple)) # N: Revealed type is "Tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]]]" \ - # E: Argument 1 to "f" has incompatible type "Tuple[int, ...]"; expected "Tuple[int, Unpack[Tuple[int, ...]]]" +reveal_type(f(var_len_tuple)) # N: Revealed type is "Tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]]]" g_args: Tuple[str, int] reveal_type(g(g_args)) # N: Revealed type is "Tuple[builtins.str, builtins.str]"