Skip to content

Commit 667e5f7

Browse files
cdce8psvalentin
authored andcommittedDec 30, 2024
Revert "Remove redundant inheritances from Iterator in builtins" (#18324)
Revert python/typeshed#12851 Ref: #18320
1 parent 67f673a commit 667e5f7

File tree

9 files changed

+368
-34
lines changed

9 files changed

+368
-34
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
From 25250cbe1f7ee0e924ac03b3f19297e1885dd13e Mon Sep 17 00:00:00 2001
2+
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
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/_asyncio.pyi | 4 +-
9+
mypy/typeshed/stdlib/builtins.pyi | 10 ++---
10+
mypy/typeshed/stdlib/csv.pyi | 4 +-
11+
mypy/typeshed/stdlib/fileinput.pyi | 6 +--
12+
mypy/typeshed/stdlib/itertools.pyi | 38 +++++++++----------
13+
mypy/typeshed/stdlib/multiprocessing/pool.pyi | 4 +-
14+
mypy/typeshed/stdlib/sqlite3/__init__.pyi | 2 +-
15+
7 files changed, 34 insertions(+), 34 deletions(-)
16+
17+
diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi
18+
index a25902661..18920cd8a 100644
19+
--- a/mypy/typeshed/stdlib/_asyncio.pyi
20+
+++ b/mypy/typeshed/stdlib/_asyncio.pyi
21+
@@ -1,6 +1,6 @@
22+
import sys
23+
from asyncio.events import AbstractEventLoop
24+
-from collections.abc import Awaitable, Callable, Coroutine, Generator
25+
+from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable
26+
from contextvars import Context
27+
from types import FrameType
28+
from typing import Any, Literal, TextIO, TypeVar
29+
@@ -13,7 +13,7 @@ _T = TypeVar("_T")
30+
_T_co = TypeVar("_T_co", covariant=True)
31+
_TaskYieldType: TypeAlias = Future[object] | None
32+
33+
-class Future(Awaitable[_T]):
34+
+class Future(Awaitable[_T], Iterable[_T]):
35+
_state: str
36+
@property
37+
def _exception(self) -> BaseException | None: ...
38+
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
39+
index 5c6d321f7..56a5969d1 100644
40+
--- a/mypy/typeshed/stdlib/builtins.pyi
41+
+++ b/mypy/typeshed/stdlib/builtins.pyi
42+
@@ -1130,7 +1130,7 @@ class frozenset(AbstractSet[_T_co]):
43+
if sys.version_info >= (3, 9):
44+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
45+
46+
-class enumerate(Generic[_T]):
47+
+class enumerate(Iterator[tuple[int, _T]]):
48+
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
49+
def __iter__(self) -> Self: ...
50+
def __next__(self) -> tuple[int, _T]: ...
51+
@@ -1324,7 +1324,7 @@ else:
52+
53+
exit: _sitebuiltins.Quitter
54+
55+
-class filter(Generic[_T]):
56+
+class filter(Iterator[_T]):
57+
@overload
58+
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
59+
@overload
60+
@@ -1389,7 +1389,7 @@ license: _sitebuiltins._Printer
61+
62+
def locals() -> dict[str, Any]: ...
63+
64+
-class map(Generic[_S]):
65+
+class map(Iterator[_S]):
66+
@overload
67+
def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
68+
@overload
69+
@@ -1632,7 +1632,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
70+
71+
quit: _sitebuiltins.Quitter
72+
73+
-class reversed(Generic[_T]):
74+
+class reversed(Iterator[_T]):
75+
@overload
76+
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
77+
@overload
78+
@@ -1693,7 +1693,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
79+
@overload
80+
def vars(object: Any = ..., /) -> dict[str, Any]: ...
81+
82+
-class zip(Generic[_T_co]):
83+
+class zip(Iterator[_T_co]):
84+
if sys.version_info >= (3, 10):
85+
@overload
86+
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...
87+
diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi
88+
index 4a82de638..ef93129d6 100644
89+
--- a/mypy/typeshed/stdlib/csv.pyi
90+
+++ b/mypy/typeshed/stdlib/csv.pyi
91+
@@ -25,7 +25,7 @@ else:
92+
from _csv import _reader as Reader, _writer as Writer
93+
94+
from _typeshed import SupportsWrite
95+
-from collections.abc import Collection, Iterable, Mapping, Sequence
96+
+from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence
97+
from typing import Any, Generic, Literal, TypeVar, overload
98+
from typing_extensions import Self
99+
100+
@@ -75,7 +75,7 @@ class excel(Dialect): ...
101+
class excel_tab(excel): ...
102+
class unix_dialect(Dialect): ...
103+
104+
-class DictReader(Generic[_T]):
105+
+class DictReader(Iterator[dict[_T | Any, str | Any]], Generic[_T]):
106+
fieldnames: Sequence[_T] | None
107+
restkey: _T | None
108+
restval: str | Any | None
109+
diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi
110+
index bf6daad0a..1e6aa78e2 100644
111+
--- a/mypy/typeshed/stdlib/fileinput.pyi
112+
+++ b/mypy/typeshed/stdlib/fileinput.pyi
113+
@@ -1,8 +1,8 @@
114+
import sys
115+
from _typeshed import AnyStr_co, StrOrBytesPath
116+
-from collections.abc import Callable, Iterable
117+
+from collections.abc import Callable, Iterable, Iterator
118+
from types import TracebackType
119+
-from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload
120+
+from typing import IO, Any, AnyStr, Literal, Protocol, overload
121+
from typing_extensions import Self, TypeAlias
122+
123+
if sys.version_info >= (3, 9):
124+
@@ -107,7 +107,7 @@ def fileno() -> int: ...
125+
def isfirstline() -> bool: ...
126+
def isstdin() -> bool: ...
127+
128+
-class FileInput(Generic[AnyStr]):
129+
+class FileInput(Iterator[AnyStr]):
130+
if sys.version_info >= (3, 10):
131+
# encoding and errors are added
132+
@overload
133+
diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi
134+
index 013c3cba1..f69665882 100644
135+
--- a/mypy/typeshed/stdlib/itertools.pyi
136+
+++ b/mypy/typeshed/stdlib/itertools.pyi
137+
@@ -29,7 +29,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
138+
139+
# Technically count can take anything that implements a number protocol and has an add method
140+
# but we can't enforce the add method
141+
-class count(Generic[_N]):
142+
+class count(Iterator[_N]):
143+
@overload
144+
def __new__(cls) -> count[int]: ...
145+
@overload
146+
@@ -39,12 +39,12 @@ class count(Generic[_N]):
147+
def __next__(self) -> _N: ...
148+
def __iter__(self) -> Self: ...
149+
150+
-class cycle(Generic[_T]):
151+
+class cycle(Iterator[_T]):
152+
def __init__(self, iterable: Iterable[_T], /) -> None: ...
153+
def __next__(self) -> _T: ...
154+
def __iter__(self) -> Self: ...
155+
156+
-class repeat(Generic[_T]):
157+
+class repeat(Iterator[_T]):
158+
@overload
159+
def __init__(self, object: _T) -> None: ...
160+
@overload
161+
@@ -53,7 +53,7 @@ class repeat(Generic[_T]):
162+
def __iter__(self) -> Self: ...
163+
def __length_hint__(self) -> int: ...
164+
165+
-class accumulate(Generic[_T]):
166+
+class accumulate(Iterator[_T]):
167+
@overload
168+
def __init__(self, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> None: ...
169+
@overload
170+
@@ -61,7 +61,7 @@ class accumulate(Generic[_T]):
171+
def __iter__(self) -> Self: ...
172+
def __next__(self) -> _T: ...
173+
174+
-class chain(Generic[_T]):
175+
+class chain(Iterator[_T]):
176+
def __init__(self, *iterables: Iterable[_T]) -> None: ...
177+
def __next__(self) -> _T: ...
178+
def __iter__(self) -> Self: ...
179+
@@ -71,22 +71,22 @@ class chain(Generic[_T]):
180+
if sys.version_info >= (3, 9):
181+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
182+
183+
-class compress(Generic[_T]):
184+
+class compress(Iterator[_T]):
185+
def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ...
186+
def __iter__(self) -> Self: ...
187+
def __next__(self) -> _T: ...
188+
189+
-class dropwhile(Generic[_T]):
190+
+class dropwhile(Iterator[_T]):
191+
def __init__(self, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> None: ...
192+
def __iter__(self) -> Self: ...
193+
def __next__(self) -> _T: ...
194+
195+
-class filterfalse(Generic[_T]):
196+
+class filterfalse(Iterator[_T]):
197+
def __init__(self, predicate: _Predicate[_T] | None, iterable: Iterable[_T], /) -> None: ...
198+
def __iter__(self) -> Self: ...
199+
def __next__(self) -> _T: ...
200+
201+
-class groupby(Generic[_T_co, _S_co]):
202+
+class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]):
203+
@overload
204+
def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ...
205+
@overload
206+
@@ -94,7 +94,7 @@ class groupby(Generic[_T_co, _S_co]):
207+
def __iter__(self) -> Self: ...
208+
def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: ...
209+
210+
-class islice(Generic[_T]):
211+
+class islice(Iterator[_T]):
212+
@overload
213+
def __init__(self, iterable: Iterable[_T], stop: int | None, /) -> None: ...
214+
@overload
215+
@@ -102,19 +102,19 @@ class islice(Generic[_T]):
216+
def __iter__(self) -> Self: ...
217+
def __next__(self) -> _T: ...
218+
219+
-class starmap(Generic[_T_co]):
220+
+class starmap(Iterator[_T_co]):
221+
def __new__(cls, function: Callable[..., _T], iterable: Iterable[Iterable[Any]], /) -> starmap[_T]: ...
222+
def __iter__(self) -> Self: ...
223+
def __next__(self) -> _T_co: ...
224+
225+
-class takewhile(Generic[_T]):
226+
+class takewhile(Iterator[_T]):
227+
def __init__(self, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> None: ...
228+
def __iter__(self) -> Self: ...
229+
def __next__(self) -> _T: ...
230+
231+
def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ...
232+
233+
-class zip_longest(Generic[_T_co]):
234+
+class zip_longest(Iterator[_T_co]):
235+
# one iterable (fillvalue doesn't matter)
236+
@overload
237+
def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = ...) -> zip_longest[tuple[_T1]]: ...
238+
@@ -192,7 +192,7 @@ class zip_longest(Generic[_T_co]):
239+
def __iter__(self) -> Self: ...
240+
def __next__(self) -> _T_co: ...
241+
242+
-class product(Generic[_T_co]):
243+
+class product(Iterator[_T_co]):
244+
@overload
245+
def __new__(cls, iter1: Iterable[_T1], /) -> product[tuple[_T1]]: ...
246+
@overload
247+
@@ -277,7 +277,7 @@ class product(Generic[_T_co]):
248+
def __iter__(self) -> Self: ...
249+
def __next__(self) -> _T_co: ...
250+
251+
-class permutations(Generic[_T_co]):
252+
+class permutations(Iterator[_T_co]):
253+
@overload
254+
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> permutations[tuple[_T, _T]]: ...
255+
@overload
256+
@@ -291,7 +291,7 @@ class permutations(Generic[_T_co]):
257+
def __iter__(self) -> Self: ...
258+
def __next__(self) -> _T_co: ...
259+
260+
-class combinations(Generic[_T_co]):
261+
+class combinations(Iterator[_T_co]):
262+
@overload
263+
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ...
264+
@overload
265+
@@ -305,7 +305,7 @@ class combinations(Generic[_T_co]):
266+
def __iter__(self) -> Self: ...
267+
def __next__(self) -> _T_co: ...
268+
269+
-class combinations_with_replacement(Generic[_T_co]):
270+
+class combinations_with_replacement(Iterator[_T_co]):
271+
@overload
272+
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations_with_replacement[tuple[_T, _T]]: ...
273+
@overload
274+
@@ -320,13 +320,13 @@ class combinations_with_replacement(Generic[_T_co]):
275+
def __next__(self) -> _T_co: ...
276+
277+
if sys.version_info >= (3, 10):
278+
- class pairwise(Generic[_T_co]):
279+
+ class pairwise(Iterator[_T_co]):
280+
def __new__(cls, iterable: Iterable[_T], /) -> pairwise[tuple[_T, _T]]: ...
281+
def __iter__(self) -> Self: ...
282+
def __next__(self) -> _T_co: ...
283+
284+
if sys.version_info >= (3, 12):
285+
- class batched(Generic[_T_co]):
286+
+ class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]):
287+
if sys.version_info >= (3, 13):
288+
def __new__(cls, iterable: Iterable[_T_co], n: int, *, strict: bool = False) -> Self: ...
289+
else:
290+
diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
291+
index 61d6d0781..950ed1d8c 100644
292+
--- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi
293+
+++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
294+
@@ -1,5 +1,5 @@
295+
import sys
296+
-from collections.abc import Callable, Iterable, Mapping
297+
+from collections.abc import Callable, Iterable, Iterator, Mapping
298+
from types import TracebackType
299+
from typing import Any, Final, Generic, TypeVar
300+
from typing_extensions import Self
301+
@@ -36,7 +36,7 @@ class MapResult(ApplyResult[list[_T]]):
302+
error_callback: Callable[[BaseException], object] | None,
303+
) -> None: ...
304+
305+
-class IMapIterator(Generic[_T]):
306+
+class IMapIterator(Iterator[_T]):
307+
def __init__(self, pool: Pool) -> None: ...
308+
def __iter__(self) -> Self: ...
309+
def next(self, timeout: float | None = None) -> _T: ...
310+
diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
311+
index bc0ff6469..730404bde 100644
312+
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
313+
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
314+
@@ -397,7 +397,7 @@ class Connection:
315+
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None, /
316+
) -> Literal[False]: ...
317+
318+
-class Cursor:
319+
+class Cursor(Iterator[Any]):
320+
arraysize: int
321+
@property
322+
def connection(self) -> Connection: ...
323+
--
324+
2.47.1

‎mypy/typeshed/stdlib/_asyncio.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from asyncio.events import AbstractEventLoop
3-
from collections.abc import Awaitable, Callable, Coroutine, Generator
3+
from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable
44
from contextvars import Context
55
from types import FrameType
66
from typing import Any, Literal, TextIO, TypeVar
@@ -13,7 +13,7 @@ _T = TypeVar("_T")
1313
_T_co = TypeVar("_T_co", covariant=True)
1414
_TaskYieldType: TypeAlias = Future[object] | None
1515

16-
class Future(Awaitable[_T]):
16+
class Future(Awaitable[_T], Iterable[_T]):
1717
_state: str
1818
@property
1919
def _exception(self) -> BaseException | None: ...

‎mypy/typeshed/stdlib/builtins.pyi

+5-5
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]: ...
@@ -1322,7 +1322,7 @@ else:
13221322

13231323
def exit(code: sys._ExitCode = None) -> NoReturn: ...
13241324

1325-
class filter(Generic[_T]):
1325+
class filter(Iterator[_T]):
13261326
@overload
13271327
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
13281328
@overload
@@ -1383,7 +1383,7 @@ def len(obj: Sized, /) -> int: ...
13831383
def license() -> None: ...
13841384
def locals() -> dict[str, Any]: ...
13851385

1386-
class map(Generic[_S]):
1386+
class map(Iterator[_S]):
13871387
@overload
13881388
def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
13891389
@overload
@@ -1625,7 +1625,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ...
16251625
def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ...
16261626
def quit(code: sys._ExitCode = None) -> NoReturn: ...
16271627

1628-
class reversed(Generic[_T]):
1628+
class reversed(Iterator[_T]):
16291629
@overload
16301630
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
16311631
@overload
@@ -1686,7 +1686,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
16861686
@overload
16871687
def vars(object: Any = ..., /) -> dict[str, Any]: ...
16881688

1689-
class zip(Generic[_T_co]):
1689+
class zip(Iterator[_T_co]):
16901690
if sys.version_info >= (3, 10):
16911691
@overload
16921692
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...

0 commit comments

Comments
 (0)