Skip to content

Commit e05770d

Browse files
authored
Sync typeshed (#18403)
Source commit: python/typeshed@b66d6cf
1 parent 9bf5169 commit e05770d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2187
-473
lines changed

misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 25250cbe1f7ee0e924ac03b3f19297e1885dd13e Mon Sep 17 00:00:00 2001
1+
From abc5225e3c69d7ae8f3388c87260fe496efaecac Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
33
Date: Sat, 21 Dec 2024 22:36:38 +0100
44
Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
@@ -15,7 +15,7 @@ Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
1515
7 files changed, 34 insertions(+), 34 deletions(-)
1616

1717
diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi
18-
index a25902661..18920cd8a 100644
18+
index 89cdff6cc..1397e579d 100644
1919
--- a/mypy/typeshed/stdlib/_asyncio.pyi
2020
+++ b/mypy/typeshed/stdlib/_asyncio.pyi
2121
@@ -1,6 +1,6 @@
@@ -36,7 +36,7 @@ index a25902661..18920cd8a 100644
3636
@property
3737
def _exception(self) -> BaseException | None: ...
3838
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
39-
index 5c6d321f7..56a5969d1 100644
39+
index b75e34fc5..526406acc 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
4242
@@ -1130,7 +1130,7 @@ class frozenset(AbstractSet[_T_co]):
@@ -64,7 +64,7 @@ index 5c6d321f7..56a5969d1 100644
6464
-class map(Generic[_S]):
6565
+class map(Iterator[_S]):
6666
@overload
67-
def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
67+
def __new__(cls, func: Callable[[_T1], _S], iterable: Iterable[_T1], /) -> Self: ...
6868
@overload
6969
@@ -1632,7 +1632,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
7070

@@ -131,7 +131,7 @@ index bf6daad0a..1e6aa78e2 100644
131131
# encoding and errors are added
132132
@overload
133133
diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi
134-
index 013c3cba1..f69665882 100644
134+
index 55b0814ac..675533d44 100644
135135
--- a/mypy/typeshed/stdlib/itertools.pyi
136136
+++ b/mypy/typeshed/stdlib/itertools.pyi
137137
@@ -29,7 +29,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
@@ -149,14 +149,14 @@ index 013c3cba1..f69665882 100644
149149

150150
-class cycle(Generic[_T]):
151151
+class cycle(Iterator[_T]):
152-
def __init__(self, iterable: Iterable[_T], /) -> None: ...
152+
def __new__(cls, iterable: Iterable[_T], /) -> Self: ...
153153
def __next__(self) -> _T: ...
154154
def __iter__(self) -> Self: ...
155155

156156
-class repeat(Generic[_T]):
157157
+class repeat(Iterator[_T]):
158158
@overload
159-
def __init__(self, object: _T) -> None: ...
159+
def __new__(cls, object: _T) -> Self: ...
160160
@overload
161161
@@ -53,7 +53,7 @@ class repeat(Generic[_T]):
162162
def __iter__(self) -> Self: ...
@@ -165,15 +165,15 @@ index 013c3cba1..f69665882 100644
165165
-class accumulate(Generic[_T]):
166166
+class accumulate(Iterator[_T]):
167167
@overload
168-
def __init__(self, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> None: ...
168+
def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> Self: ...
169169
@overload
170170
@@ -61,7 +61,7 @@ class accumulate(Generic[_T]):
171171
def __iter__(self) -> Self: ...
172172
def __next__(self) -> _T: ...
173173

174174
-class chain(Generic[_T]):
175175
+class chain(Iterator[_T]):
176-
def __init__(self, *iterables: Iterable[_T]) -> None: ...
176+
def __new__(cls, *iterables: Iterable[_T]) -> Self: ...
177177
def __next__(self) -> _T: ...
178178
def __iter__(self) -> Self: ...
179179
@@ -71,22 +71,22 @@ class chain(Generic[_T]):
@@ -182,19 +182,19 @@ index 013c3cba1..f69665882 100644
182182

183183
-class compress(Generic[_T]):
184184
+class compress(Iterator[_T]):
185-
def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ...
185+
def __new__(cls, data: Iterable[_T], selectors: Iterable[Any]) -> Self: ...
186186
def __iter__(self) -> Self: ...
187187
def __next__(self) -> _T: ...
188188

189189
-class dropwhile(Generic[_T]):
190190
+class dropwhile(Iterator[_T]):
191-
def __init__(self, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> None: ...
191+
def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ...
192192
def __iter__(self) -> Self: ...
193193
def __next__(self) -> _T: ...
194194

195195
-class filterfalse(Generic[_T]):
196196
+class filterfalse(Iterator[_T]):
197-
def __init__(self, predicate: _Predicate[_T] | None, iterable: Iterable[_T], /) -> None: ...
197+
def __new__(cls, function: _Predicate[_T] | None, iterable: Iterable[_T], /) -> Self: ...
198198
def __iter__(self) -> Self: ...
199199
def __next__(self) -> _T: ...
200200

@@ -210,7 +210,7 @@ index 013c3cba1..f69665882 100644
210210
-class islice(Generic[_T]):
211211
+class islice(Iterator[_T]):
212212
@overload
213-
def __init__(self, iterable: Iterable[_T], stop: int | None, /) -> None: ...
213+
def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ...
214214
@overload
215215
@@ -102,19 +102,19 @@ class islice(Generic[_T]):
216216
def __iter__(self) -> Self: ...
@@ -224,7 +224,7 @@ index 013c3cba1..f69665882 100644
224224

225225
-class takewhile(Generic[_T]):
226226
+class takewhile(Iterator[_T]):
227-
def __init__(self, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> None: ...
227+
def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ...
228228
def __iter__(self) -> Self: ...
229229
def __next__(self) -> _T: ...
230230

@@ -288,17 +288,17 @@ index 013c3cba1..f69665882 100644
288288
def __new__(cls, iterable: Iterable[_T_co], n: int, *, strict: bool = False) -> Self: ...
289289
else:
290290
diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
291-
index 61d6d0781..950ed1d8c 100644
291+
index 2937d45e3..93197e5d4 100644
292292
--- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi
293293
+++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
294294
@@ -1,5 +1,5 @@
295295
import sys
296296
-from collections.abc import Callable, Iterable, Mapping
297297
+from collections.abc import Callable, Iterable, Iterator, Mapping
298+
from multiprocessing.context import DefaultContext, Process
298299
from types import TracebackType
299300
from typing import Any, Final, Generic, TypeVar
300-
from typing_extensions import Self
301-
@@ -36,7 +36,7 @@ class MapResult(ApplyResult[list[_T]]):
301+
@@ -37,7 +37,7 @@ class MapResult(ApplyResult[list[_T]]):
302302
error_callback: Callable[[BaseException], object] | None,
303303
) -> None: ...
304304

@@ -308,7 +308,7 @@ index 61d6d0781..950ed1d8c 100644
308308
def __iter__(self) -> Self: ...
309309
def next(self, timeout: float | None = None) -> _T: ...
310310
diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
311-
index bc0ff6469..730404bde 100644
311+
index b83516b4d..724bc3166 100644
312312
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
313313
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
314314
@@ -397,7 +397,7 @@ class Connection:

mypy/typeshed/stdlib/_asyncio.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
6565
self,
6666
coro: _TaskCompatibleCoro[_T_co],
6767
*,
68-
loop: AbstractEventLoop = ...,
68+
loop: AbstractEventLoop | None = None,
6969
name: str | None = ...,
7070
context: Context | None = None,
7171
eager_start: bool = False,
@@ -75,13 +75,13 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
7575
self,
7676
coro: _TaskCompatibleCoro[_T_co],
7777
*,
78-
loop: AbstractEventLoop = ...,
78+
loop: AbstractEventLoop | None = None,
7979
name: str | None = ...,
8080
context: Context | None = None,
8181
) -> None: ...
8282
else:
8383
def __init__(
84-
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop = ..., name: str | None = ...
84+
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, name: str | None = ...
8585
) -> None: ...
8686

8787
if sys.version_info >= (3, 12):

mypy/typeshed/stdlib/_blake2.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class blake2b:
2222
digest_size: int
2323
name: str
2424
if sys.version_info >= (3, 9):
25-
def __init__(
26-
self,
25+
def __new__(
26+
cls,
2727
data: ReadableBuffer = b"",
2828
/,
2929
*,
@@ -39,10 +39,10 @@ class blake2b:
3939
inner_size: int = 0,
4040
last_node: bool = False,
4141
usedforsecurity: bool = True,
42-
) -> None: ...
42+
) -> Self: ...
4343
else:
44-
def __init__(
45-
self,
44+
def __new__(
45+
cls,
4646
data: ReadableBuffer = b"",
4747
/,
4848
*,
@@ -57,7 +57,7 @@ class blake2b:
5757
node_depth: int = 0,
5858
inner_size: int = 0,
5959
last_node: bool = False,
60-
) -> None: ...
60+
) -> Self: ...
6161

6262
def copy(self) -> Self: ...
6363
def digest(self) -> bytes: ...
@@ -74,8 +74,8 @@ class blake2s:
7474
digest_size: int
7575
name: str
7676
if sys.version_info >= (3, 9):
77-
def __init__(
78-
self,
77+
def __new__(
78+
cls,
7979
data: ReadableBuffer = b"",
8080
/,
8181
*,
@@ -91,10 +91,10 @@ class blake2s:
9191
inner_size: int = 0,
9292
last_node: bool = False,
9393
usedforsecurity: bool = True,
94-
) -> None: ...
94+
) -> Self: ...
9595
else:
96-
def __init__(
97-
self,
96+
def __new__(
97+
cls,
9898
data: ReadableBuffer = b"",
9999
/,
100100
*,
@@ -109,7 +109,7 @@ class blake2s:
109109
node_depth: int = 0,
110110
inner_size: int = 0,
111111
last_node: bool = False,
112-
) -> None: ...
112+
) -> Self: ...
113113

114114
def copy(self) -> Self: ...
115115
def digest(self) -> bytes: ...

mypy/typeshed/stdlib/_bz2.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import sys
12
from _typeshed import ReadableBuffer
23
from typing import final
4+
from typing_extensions import Self
35

46
@final
57
class BZ2Compressor:
6-
def __init__(self, compresslevel: int = 9) -> None: ...
8+
if sys.version_info >= (3, 12):
9+
def __new__(cls, compresslevel: int = 9, /) -> Self: ...
10+
else:
11+
def __init__(self, compresslevel: int = 9, /) -> None: ...
12+
713
def compress(self, data: ReadableBuffer, /) -> bytes: ...
814
def flush(self) -> bytes: ...
915

mypy/typeshed/stdlib/_collections_abc.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from typing import ( # noqa: Y022,Y038
88
AsyncIterator as AsyncIterator,
99
Awaitable as Awaitable,
1010
Callable as Callable,
11+
ClassVar,
1112
Collection as Collection,
1213
Container as Container,
1314
Coroutine as Coroutine,
@@ -74,6 +75,7 @@ _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
7475
class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented
7576
def __eq__(self, value: object, /) -> bool: ...
7677
def __reversed__(self) -> Iterator[_KT_co]: ...
78+
__hash__: ClassVar[None] # type: ignore[assignment]
7779
if sys.version_info >= (3, 13):
7880
def isdisjoint(self, other: Iterable[_KT_co], /) -> bool: ...
7981
if sys.version_info >= (3, 10):
@@ -91,6 +93,7 @@ class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented
9193
class dict_items(ItemsView[_KT_co, _VT_co]): # undocumented
9294
def __eq__(self, value: object, /) -> bool: ...
9395
def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
96+
__hash__: ClassVar[None] # type: ignore[assignment]
9497
if sys.version_info >= (3, 13):
9598
def isdisjoint(self, other: Iterable[tuple[_KT_co, _VT_co]], /) -> bool: ...
9699
if sys.version_info >= (3, 10):

mypy/typeshed/stdlib/_contextvars.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from collections.abc import Callable, Iterator, Mapping
33
from typing import Any, ClassVar, Generic, TypeVar, final, overload
4-
from typing_extensions import ParamSpec
4+
from typing_extensions import ParamSpec, Self
55

66
if sys.version_info >= (3, 9):
77
from types import GenericAlias
@@ -13,9 +13,9 @@ _P = ParamSpec("_P")
1313
@final
1414
class ContextVar(Generic[_T]):
1515
@overload
16-
def __init__(self, name: str) -> None: ...
16+
def __new__(cls, name: str) -> Self: ...
1717
@overload
18-
def __init__(self, name: str, *, default: _T) -> None: ...
18+
def __new__(cls, name: str, *, default: _T) -> Self: ...
1919
def __hash__(self) -> int: ...
2020
@property
2121
def name(self) -> str: ...
@@ -37,6 +37,7 @@ class Token(Generic[_T]):
3737
@property
3838
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
3939
MISSING: ClassVar[object]
40+
__hash__: ClassVar[None] # type: ignore[assignment]
4041
if sys.version_info >= (3, 9):
4142
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4243

@@ -55,6 +56,7 @@ class Context(Mapping[ContextVar[Any], Any]):
5556
def get(self, key: ContextVar[_T], default: _D, /) -> _T | _D: ...
5657
def run(self, callable: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
5758
def copy(self) -> Context: ...
59+
__hash__: ClassVar[None] # type: ignore[assignment]
5860
def __getitem__(self, key: ContextVar[_T], /) -> _T: ...
5961
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
6062
def __len__(self) -> int: ...

mypy/typeshed/stdlib/_csv.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Dialect:
3232
lineterminator: str
3333
quoting: _QuotingType
3434
strict: bool
35-
def __init__(
36-
self,
35+
def __new__(
36+
cls,
3737
dialect: _DialectLike | None = ...,
3838
delimiter: str = ",",
3939
doublequote: bool = True,
@@ -43,7 +43,7 @@ class Dialect:
4343
quoting: _QuotingType = 0,
4444
skipinitialspace: bool = False,
4545
strict: bool = False,
46-
) -> None: ...
46+
) -> Self: ...
4747

4848
if sys.version_info >= (3, 10):
4949
# This class calls itself _csv.reader.
@@ -115,7 +115,7 @@ def reader(
115115
) -> _reader: ...
116116
def register_dialect(
117117
name: str,
118-
dialect: type[Dialect] = ...,
118+
dialect: type[Dialect | csv.Dialect] = ...,
119119
*,
120120
delimiter: str = ",",
121121
quotechar: str | None = '"',

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,18 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType):
169169
# Abstract attribute that must be defined on subclasses
170170
_flags_: ClassVar[int]
171171
@overload
172-
def __init__(self) -> None: ...
172+
def __new__(cls) -> Self: ...
173173
@overload
174-
def __init__(self, address: int, /) -> None: ...
174+
def __new__(cls, address: int, /) -> Self: ...
175175
@overload
176-
def __init__(self, callable: Callable[..., Any], /) -> None: ...
176+
def __new__(cls, callable: Callable[..., Any], /) -> Self: ...
177177
@overload
178-
def __init__(self, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> None: ...
178+
def __new__(cls, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> Self: ...
179179
if sys.platform == "win32":
180180
@overload
181-
def __init__(
182-
self, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
183-
) -> None: ...
181+
def __new__(
182+
cls, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
183+
) -> Self: ...
184184

185185
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
186186

mypy/typeshed/stdlib/_curses.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
2-
from _typeshed import ReadOnlyBuffer, SupportsRead
2+
from _typeshed import ReadOnlyBuffer, SupportsRead, SupportsWrite
33
from curses import _ncurses_version
4-
from typing import IO, Any, final, overload
4+
from typing import Any, final, overload
55
from typing_extensions import TypeAlias
66

77
# NOTE: This module is ordinarily only available on Unix, but the windows-curses
@@ -517,7 +517,7 @@ class window: # undocumented
517517
def overwrite(
518518
self, destwin: window, sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int
519519
) -> None: ...
520-
def putwin(self, file: IO[Any], /) -> None: ...
520+
def putwin(self, file: SupportsWrite[bytes], /) -> None: ...
521521
def redrawln(self, beg: int, num: int, /) -> None: ...
522522
def redrawwin(self) -> None: ...
523523
@overload

0 commit comments

Comments
 (0)