Skip to content

Commit

Permalink
Revert "Remove redundant inheritances from Iterator in builtins"
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Dec 21, 2024
1 parent 924f818 commit 88aaa82
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 25250cbe1f7ee0e924ac03b3f19297e1885dd13e Mon Sep 17 00:00:00 2001
From: Marc Mueller <[email protected]>
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
10 changes: 5 additions & 5 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]: ...
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]"

0 comments on commit 88aaa82

Please sign in to comment.