diff --git a/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch new file mode 100644 index 000000000000..33ee7e0be932 --- /dev/null +++ b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch @@ -0,0 +1,61 @@ +From 25250cbe1f7ee0e924ac03b3f19297e1885dd13e Mon Sep 17 00:00:00 2001 +From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> +Date: Sat, 21 Dec 2024 22:36:38 +0100 +Subject: [PATCH] Revert Remove redundant inheritances from Iterator in + builtins + +--- + mypy/typeshed/stdlib/builtins.pyi | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi +index 5c6d321f7..56a5969d1 100644 +--- a/mypy/typeshed/stdlib/builtins.pyi ++++ b/mypy/typeshed/stdlib/builtins.pyi +@@ -1130,7 +1130,7 @@ class frozenset(AbstractSet[_T_co]): + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... + +-class enumerate(Generic[_T]): ++class enumerate(Iterator[tuple[int, _T]]): + def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... + def __iter__(self) -> Self: ... + def __next__(self) -> tuple[int, _T]: ... +@@ -1324,7 +1324,7 @@ else: + + exit: _sitebuiltins.Quitter + +-class filter(Generic[_T]): ++class filter(Iterator[_T]): + @overload + def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... + @overload +@@ -1389,7 +1389,7 @@ license: _sitebuiltins._Printer + + def locals() -> dict[str, Any]: ... + +-class map(Generic[_S]): ++class map(Iterator[_S]): + @overload + def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ... + @overload +@@ -1632,7 +1632,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex + + quit: _sitebuiltins.Quitter + +-class reversed(Generic[_T]): ++class reversed(Iterator[_T]): + @overload + def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc] + @overload +@@ -1693,7 +1693,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... + @overload + def vars(object: Any = ..., /) -> dict[str, Any]: ... + +-class zip(Generic[_T_co]): ++class zip(Iterator[_T_co]): + if sys.version_info >= (3, 10): + @overload + def __new__(cls, *, strict: bool = ...) -> zip[Any]: ... +-- +2.47.1 diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 5c6d321f772e..56a5969d102a 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -1130,7 +1130,7 @@ class frozenset(AbstractSet[_T_co]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... -class enumerate(Generic[_T]): +class enumerate(Iterator[tuple[int, _T]]): def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... @@ -1324,7 +1324,7 @@ else: exit: _sitebuiltins.Quitter -class filter(Generic[_T]): +class filter(Iterator[_T]): @overload def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... @overload @@ -1389,7 +1389,7 @@ license: _sitebuiltins._Printer def locals() -> dict[str, Any]: ... -class map(Generic[_S]): +class map(Iterator[_S]): @overload def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ... @overload @@ -1632,7 +1632,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex quit: _sitebuiltins.Quitter -class reversed(Generic[_T]): +class reversed(Iterator[_T]): @overload def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc] @overload @@ -1693,7 +1693,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... @overload def vars(object: Any = ..., /) -> dict[str, Any]: ... -class zip(Generic[_T_co]): +class zip(Iterator[_T_co]): if sys.version_info >= (3, 10): @overload def __new__(cls, *, strict: bool = ...) -> zip[Any]: ... diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 70003545754c..397ccbb0d3f8 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -2181,3 +2181,13 @@ class Status(Enum): def imperfect(status: Status) -> str: return status.name.lower() + +[case testUnpackIteratorBuiltins] +# Regression test for https://github.com/python/mypy/issues/18320 +# Caused by https://github.com/python/typeshed/pull/12851 +x = [1, 2] +reveal_type([*reversed(x)]) +reveal_type([*map(str, x)]) +[out] +_testUnpackIteratorBuiltins.py:4: note: Revealed type is "builtins.list[builtins.int]" +_testUnpackIteratorBuiltins.py:5: note: Revealed type is "builtins.list[builtins.str]"