Skip to content

Commit 88aaa82

Browse files
committed
Revert "Remove redundant inheritances from Iterator in builtins"
1 parent 924f818 commit 88aaa82

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
From 25250cbe1f7ee0e924ac03b3f19297e1885dd13e Mon Sep 17 00:00:00 2001
2+
From: Marc Mueller <[email protected]>
3+
Date: Sat, 21 Dec 2024 22:36:38 +0100
4+
Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
5+
builtins
6+
7+
---
8+
mypy/typeshed/stdlib/builtins.pyi | 10 +++++-----
9+
1 file changed, 5 insertions(+), 5 deletions(-)
10+
11+
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
12+
index 5c6d321f7..56a5969d1 100644
13+
--- a/mypy/typeshed/stdlib/builtins.pyi
14+
+++ b/mypy/typeshed/stdlib/builtins.pyi
15+
@@ -1130,7 +1130,7 @@ class frozenset(AbstractSet[_T_co]):
16+
if sys.version_info >= (3, 9):
17+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
18+
19+
-class enumerate(Generic[_T]):
20+
+class enumerate(Iterator[tuple[int, _T]]):
21+
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
22+
def __iter__(self) -> Self: ...
23+
def __next__(self) -> tuple[int, _T]: ...
24+
@@ -1324,7 +1324,7 @@ else:
25+
26+
exit: _sitebuiltins.Quitter
27+
28+
-class filter(Generic[_T]):
29+
+class filter(Iterator[_T]):
30+
@overload
31+
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
32+
@overload
33+
@@ -1389,7 +1389,7 @@ license: _sitebuiltins._Printer
34+
35+
def locals() -> dict[str, Any]: ...
36+
37+
-class map(Generic[_S]):
38+
+class map(Iterator[_S]):
39+
@overload
40+
def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
41+
@overload
42+
@@ -1632,7 +1632,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
43+
44+
quit: _sitebuiltins.Quitter
45+
46+
-class reversed(Generic[_T]):
47+
+class reversed(Iterator[_T]):
48+
@overload
49+
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
50+
@overload
51+
@@ -1693,7 +1693,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
52+
@overload
53+
def vars(object: Any = ..., /) -> dict[str, Any]: ...
54+
55+
-class zip(Generic[_T_co]):
56+
+class zip(Iterator[_T_co]):
57+
if sys.version_info >= (3, 10):
58+
@overload
59+
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...
60+
--
61+
2.47.1

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ class frozenset(AbstractSet[_T_co]):
11301130
if sys.version_info >= (3, 9):
11311131
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
11321132

1133-
class enumerate(Generic[_T]):
1133+
class enumerate(Iterator[tuple[int, _T]]):
11341134
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
11351135
def __iter__(self) -> Self: ...
11361136
def __next__(self) -> tuple[int, _T]: ...
@@ -1324,7 +1324,7 @@ else:
13241324

13251325
exit: _sitebuiltins.Quitter
13261326

1327-
class filter(Generic[_T]):
1327+
class filter(Iterator[_T]):
13281328
@overload
13291329
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
13301330
@overload
@@ -1389,7 +1389,7 @@ license: _sitebuiltins._Printer
13891389

13901390
def locals() -> dict[str, Any]: ...
13911391

1392-
class map(Generic[_S]):
1392+
class map(Iterator[_S]):
13931393
@overload
13941394
def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
13951395
@overload
@@ -1632,7 +1632,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
16321632

16331633
quit: _sitebuiltins.Quitter
16341634

1635-
class reversed(Generic[_T]):
1635+
class reversed(Iterator[_T]):
16361636
@overload
16371637
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
16381638
@overload
@@ -1693,7 +1693,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
16931693
@overload
16941694
def vars(object: Any = ..., /) -> dict[str, Any]: ...
16951695

1696-
class zip(Generic[_T_co]):
1696+
class zip(Iterator[_T_co]):
16971697
if sys.version_info >= (3, 10):
16981698
@overload
16991699
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...

test-data/unit/pythoneval.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,3 +2181,13 @@ class Status(Enum):
21812181

21822182
def imperfect(status: Status) -> str:
21832183
return status.name.lower()
2184+
2185+
[case testUnpackIteratorBuiltins]
2186+
# Regression test for https://github.com/python/mypy/issues/18320
2187+
# Caused by https://github.com/python/typeshed/pull/12851
2188+
x = [1, 2]
2189+
reveal_type([*reversed(x)])
2190+
reveal_type([*map(str, x)])
2191+
[out]
2192+
_testUnpackIteratorBuiltins.py:4: note: Revealed type is "builtins.list[builtins.int]"
2193+
_testUnpackIteratorBuiltins.py:5: note: Revealed type is "builtins.list[builtins.str]"

0 commit comments

Comments
 (0)