Skip to content

Commit b6b929b

Browse files
authored
Sync typeshed (#20605)
Source commit: python/typeshed@b94c9e8
1 parent 6424d0b commit b6b929b

Some content is hidden

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

56 files changed

+586
-311
lines changed

misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 84a9d586544a0408d4654f57f83a93cb048070fb Mon Sep 17 00:00:00 2001
1+
From b6d495c10e79fb56ff64f8fb90c87894090f9cbe Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
33
Date: Sat, 15 Feb 2025 20:11:06 +0100
44
Subject: [PATCH] Partially revert Clean up argparse hacks
@@ -8,7 +8,7 @@ Subject: [PATCH] Partially revert Clean up argparse hacks
88
1 file changed, 5 insertions(+), 3 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi
11-
index b9fa31139..3c3ba116a 100644
11+
index ae99eb036..c87b8f4fc 100644
1212
--- a/mypy/typeshed/stdlib/argparse.pyi
1313
+++ b/mypy/typeshed/stdlib/argparse.pyi
1414
@@ -2,7 +2,7 @@ import sys
@@ -41,5 +41,5 @@ index b9fa31139..3c3ba116a 100644
4141
default: Any = ...,
4242
type: _ActionType = ...,
4343
--
44-
2.50.1
44+
2.52.0
4545

misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 3229a6066cff3d80d6cb923322c2d42a300d0be3 Mon Sep 17 00:00:00 2001
1+
From ed11d7e0204868ef1a43c17ed950372b1d78f497 Mon Sep 17 00:00:00 2001
22
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
33
Date: Mon, 26 Sep 2022 12:55:07 -0700
44
Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
@@ -8,18 +8,18 @@ Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
88
1 file changed, 1 insertion(+), 99 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11-
index 969d16876..044e264d2 100644
11+
index 693dd0b77..8acdeadff 100644
1212
--- a/mypy/typeshed/stdlib/builtins.pyi
1313
+++ b/mypy/typeshed/stdlib/builtins.pyi
14-
@@ -63,7 +63,6 @@ from typing import ( # noqa: Y022,UP035
14+
@@ -64,7 +64,6 @@ from typing import ( # noqa: Y022,UP035
1515
from typing_extensions import ( # noqa: Y023
1616
Concatenate,
1717
Literal,
1818
- LiteralString,
1919
ParamSpec,
2020
Self,
2121
TypeAlias,
22-
@@ -480,31 +479,16 @@ class str(Sequence[str]):
22+
@@ -482,31 +481,16 @@ class str(Sequence[str]):
2323
def __new__(cls, object: object = "") -> Self: ...
2424
@overload
2525
def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ...
@@ -51,7 +51,7 @@ index 969d16876..044e264d2 100644
5151
def format(self, *args: object, **kwargs: object) -> str: ...
5252
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
5353
def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
54-
@@ -520,98 +504,34 @@ class str(Sequence[str]):
54+
@@ -522,98 +506,34 @@ class str(Sequence[str]):
5555
def isspace(self) -> bool: ...
5656
def istitle(self) -> bool: ...
5757
def isupper(self) -> bool: ...
@@ -150,7 +150,7 @@ index 969d16876..044e264d2 100644
150150
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
151151
@staticmethod
152152
@overload
153-
@@ -622,39 +542,21 @@ class str(Sequence[str]):
153+
@@ -624,39 +544,21 @@ class str(Sequence[str]):
154154
@staticmethod
155155
@overload
156156
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
@@ -192,5 +192,5 @@ index 969d16876..044e264d2 100644
192192
def __getnewargs__(self) -> tuple[str]: ...
193193
def __format__(self, format_spec: str, /) -> str: ...
194194
--
195-
2.51.1
195+
2.52.0
196196

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 7678bc3f80e4d3f04a0ff0ee3a7d51f49ae4c465 Mon Sep 17 00:00:00 2001
1+
From 69791281c2c5e919cea9a77c4a771f79d9e70384 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
@@ -36,10 +36,10 @@ index d663f5d93..f43178e4d 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 044e264d2..6d813f172 100644
39+
index 8acdeadff..5a3bb5908 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
42-
@@ -1210,7 +1210,7 @@ class frozenset(AbstractSet[_T_co]):
42+
@@ -1226,7 +1226,7 @@ class frozenset(AbstractSet[_T_co]):
4343
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4444

4545
@disjoint_base
@@ -48,7 +48,7 @@ index 044e264d2..6d813f172 100644
4848
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
4949
def __iter__(self) -> Self: ...
5050
def __next__(self) -> tuple[int, _T]: ...
51-
@@ -1404,7 +1404,7 @@ else:
51+
@@ -1413,7 +1413,7 @@ else:
5252
exit: _sitebuiltins.Quitter
5353

5454
@disjoint_base
@@ -57,7 +57,7 @@ index 044e264d2..6d813f172 100644
5757
@overload
5858
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
5959
@overload
60-
@@ -1468,7 +1468,7 @@ license: _sitebuiltins._Printer
60+
@@ -1477,7 +1477,7 @@ license: _sitebuiltins._Printer
6161

6262
def locals() -> dict[str, Any]: ...
6363
@disjoint_base
@@ -66,7 +66,7 @@ index 044e264d2..6d813f172 100644
6666
# 3.14 adds `strict` argument.
6767
if sys.version_info >= (3, 14):
6868
@overload
69-
@@ -1775,7 +1775,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
69+
@@ -1784,7 +1784,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
7070
quit: _sitebuiltins.Quitter
7171

7272
@disjoint_base
@@ -75,7 +75,7 @@ index 044e264d2..6d813f172 100644
7575
@overload
7676
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
7777
@overload
78-
@@ -1839,7 +1839,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
78+
@@ -1848,7 +1848,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
7979
@overload
8080
def vars(object: Any = ..., /) -> dict[str, Any]: ...
8181
@disjoint_base
@@ -107,7 +107,7 @@ index 2c8e7109c..4ed0ab1d8 100644
107107
restkey: _T | None
108108
restval: str | Any | None
109109
diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi
110-
index 910d63814..eb942bc55 100644
110+
index 6778b7648..95164de2f 100644
111111
--- a/mypy/typeshed/stdlib/fileinput.pyi
112112
+++ b/mypy/typeshed/stdlib/fileinput.pyi
113113
@@ -1,8 +1,8 @@
@@ -118,7 +118,7 @@ index 910d63814..eb942bc55 100644
118118
from types import GenericAlias, TracebackType
119119
-from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload, type_check_only
120120
+from typing import IO, Any, AnyStr, Literal, Protocol, overload, type_check_only
121-
from typing_extensions import Self, TypeAlias
121+
from typing_extensions import Self, TypeAlias, deprecated
122122

123123
__all__ = [
124124
@@ -105,7 +105,7 @@ def fileno() -> int: ...
@@ -131,7 +131,7 @@ index 910d63814..eb942bc55 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 fe4ccbdf8..73745fe92 100644
134+
index 8a924ad8b..5c2bf7f83 100644
135135
--- a/mypy/typeshed/stdlib/itertools.pyi
136136
+++ b/mypy/typeshed/stdlib/itertools.pyi
137137
@@ -28,7 +28,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
@@ -166,7 +166,7 @@ index fe4ccbdf8..73745fe92 100644
166166
-class accumulate(Generic[_T]):
167167
+class accumulate(Iterator[_T]):
168168
@overload
169-
def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> Self: ...
169+
def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ...
170170
@overload
171171
@@ -64,7 +64,7 @@ class accumulate(Generic[_T]):
172172
def __next__(self) -> _T: ...
@@ -239,7 +239,7 @@ index fe4ccbdf8..73745fe92 100644
239239
+class zip_longest(Iterator[_T_co]):
240240
# one iterable (fillvalue doesn't matter)
241241
@overload
242-
def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = ...) -> zip_longest[tuple[_T1]]: ...
242+
def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ...
243243
@@ -202,7 +202,7 @@ class zip_longest(Generic[_T_co]):
244244
def __next__(self) -> _T_co: ...
245245

@@ -291,8 +291,8 @@ index fe4ccbdf8..73745fe92 100644
291291
- class batched(Generic[_T_co]):
292292
+ class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]):
293293
if sys.version_info >= (3, 13):
294-
def __new__(cls, iterable: Iterable[_T_co], n: int, *, strict: bool = False) -> Self: ...
295-
else:
294+
@overload
295+
def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ...
296296
diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
297297
index b79f9e773..f276372d0 100644
298298
--- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi
@@ -313,10 +313,10 @@ index b79f9e773..f276372d0 100644
313313
def __iter__(self) -> Self: ...
314314
def next(self, timeout: float | None = None) -> _T: ...
315315
diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
316-
index 6b0f1ba94..882cd143c 100644
316+
index 04b978b1b..e4604144f 100644
317317
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
318318
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
319-
@@ -407,7 +407,7 @@ class Connection:
319+
@@ -408,7 +408,7 @@ class Connection:
320320
) -> Literal[False]: ...
321321

322322
@disjoint_base
@@ -326,5 +326,5 @@ index 6b0f1ba94..882cd143c 100644
326326
@property
327327
def connection(self) -> Connection: ...
328328
--
329-
2.51.1
329+
2.52.0
330330

misc/typeshed_patches/0001-Revert-sum-literal-integer-change-13961.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 16b0b50ec77e470f24145071acde5274a1de53a0 Mon Sep 17 00:00:00 2001
1+
From 0e30b762e8335f02e19977c055ac7b98e707991c Mon Sep 17 00:00:00 2001
22
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
33
Date: Sat, 29 Oct 2022 12:47:21 -0700
44
Subject: [PATCH] Revert sum literal integer change (#13961)
@@ -19,10 +19,10 @@ within mypy, I might pursue upstreaming this in typeshed.
1919
1 file changed, 1 insertion(+), 1 deletion(-)
2020

2121
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
22-
index 900c4c93f..d874edd8f 100644
22+
index 5a3bb5908..0f2196070 100644
2323
--- a/mypy/typeshed/stdlib/builtins.pyi
2424
+++ b/mypy/typeshed/stdlib/builtins.pyi
25-
@@ -1782,7 +1782,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
25+
@@ -1835,7 +1835,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
2626
# without creating many false-positive errors (see #7578).
2727
# Instead, we special-case the most common examples of this: bool and literal integers.
2828
@overload
@@ -32,5 +32,5 @@ index 900c4c93f..d874edd8f 100644
3232
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
3333
@overload
3434
--
35-
2.49.0
35+
2.52.0
3636

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
From 85c0cfb55c6211c2a47c3f45d2ff28fa76f8204b Mon Sep 17 00:00:00 2001
1+
From 80a710e0e2c09612c6fc30c644f2052450e69ccd Mon Sep 17 00:00:00 2001
22
From: AlexWaygood <alex.waygood@gmail.com>
33
Date: Mon, 1 May 2023 20:34:55 +0100
4-
Subject: [PATCH] Revert typeshed ctypes change Since the plugin provides
5-
superior type checking:
6-
https://github.com/python/mypy/pull/13987#issuecomment-1310863427 A manual
7-
cherry-pick of e437cdf.
4+
Subject: [PATCH] Revert typeshed ctypes change
85

6+
The plugin provides superior type checking:
7+
https://github.com/python/mypy/pull/13987#issuecomment-1310863427
8+
A manual cherry-pick of e437cdf.
99
---
1010
mypy/typeshed/stdlib/_ctypes.pyi | 6 +-----
1111
1 file changed, 1 insertion(+), 5 deletions(-)
1212

1313
diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi
14-
index 944685646..dc8c7b2ca 100644
14+
index be7792818..b7a3fb104 100644
1515
--- a/mypy/typeshed/stdlib/_ctypes.pyi
1616
+++ b/mypy/typeshed/stdlib/_ctypes.pyi
17-
@@ -289,11 +289,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
17+
@@ -320,11 +320,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
1818
def _type_(self) -> type[_CT]: ...
1919
@_type_.setter
2020
def _type_(self, value: type[_CT]) -> None: ...
@@ -28,5 +28,5 @@ index 944685646..dc8c7b2ca 100644
2828
# TODO: These methods cannot be annotated correctly at the moment.
2929
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
3030
--
31-
2.49.0
31+
2.52.0
3232

mypy/typeshed/stdlib/_frozen_importlib_external.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from _typeshed.importlib import LoaderProtocol
99
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSequence, Sequence
1010
from importlib.machinery import ModuleSpec
1111
from importlib.metadata import DistributionFinder, PathDistribution
12-
from typing import Any, Final, Literal
12+
from typing import Any, Final, Literal, overload
1313
from typing_extensions import Self, deprecated
1414

1515
if sys.version_info >= (3, 10):
@@ -26,7 +26,13 @@ else:
2626

2727
MAGIC_NUMBER: Final[bytes]
2828

29-
def cache_from_source(path: StrPath, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ...
29+
@overload
30+
@deprecated(
31+
"The `debug_override` parameter is deprecated since Python 3.5; will be removed in Python 3.15. Use `optimization` instead."
32+
)
33+
def cache_from_source(path: StrPath, debug_override: bool, *, optimization: None = None) -> str: ...
34+
@overload
35+
def cache_from_source(path: StrPath, debug_override: None = None, *, optimization: Any | None = None) -> str: ...
3036
def source_from_cache(path: StrPath) -> str: ...
3137
def decode_source(source_bytes: ReadableBuffer) -> str: ...
3238
def spec_from_file_location(

mypy/typeshed/stdlib/_tkinter.pyi

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
2+
from _typeshed import FileDescriptorLike, Incomplete
23
from collections.abc import Callable
3-
from typing import Any, ClassVar, Final, final
4+
from typing import Any, ClassVar, Final, Literal, final, overload
45
from typing_extensions import TypeAlias, deprecated
56

67
# _tkinter is meant to be only used internally by tkinter, but some tkinter
@@ -54,22 +55,23 @@ _TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object]
5455
@final
5556
class TkappType:
5657
# Please keep in sync with tkinter.Tk
57-
def adderrorinfo(self, msg: str, /): ...
58+
def adderrorinfo(self, msg: str, /) -> None: ...
5859
def call(self, command: Any, /, *args: Any) -> Any: ...
59-
def createcommand(self, name: str, func, /): ...
60+
# TODO: Figure out what arguments the following `func` callbacks should accept
61+
def createcommand(self, name: str, func: Callable[..., object], /) -> None: ...
6062
if sys.platform != "win32":
61-
def createfilehandler(self, file, mask: int, func, /): ...
62-
def deletefilehandler(self, file, /) -> None: ...
63+
def createfilehandler(self, file: FileDescriptorLike, mask: int, func: Callable[..., object], /) -> None: ...
64+
def deletefilehandler(self, file: FileDescriptorLike, /) -> None: ...
6365

64-
def createtimerhandler(self, milliseconds: int, func, /): ...
65-
def deletecommand(self, name: str, /): ...
66-
def dooneevent(self, flags: int = 0, /): ...
66+
def createtimerhandler(self, milliseconds: int, func: Callable[..., object], /): ...
67+
def deletecommand(self, name: str, /) -> None: ...
68+
def dooneevent(self, flags: int = 0, /) -> int: ...
6769
def eval(self, script: str, /) -> str: ...
68-
def evalfile(self, fileName: str, /): ...
69-
def exprboolean(self, s: str, /): ...
70-
def exprdouble(self, s: str, /): ...
71-
def exprlong(self, s: str, /): ...
72-
def exprstring(self, s: str, /): ...
70+
def evalfile(self, fileName: str, /) -> str: ...
71+
def exprboolean(self, s: str, /) -> Literal[0, 1]: ...
72+
def exprdouble(self, s: str, /) -> float: ...
73+
def exprlong(self, s: str, /) -> int: ...
74+
def exprstring(self, s: str, /) -> str: ...
7375
def getboolean(self, arg, /) -> bool: ...
7476
def getdouble(self, arg, /) -> float: ...
7577
def getint(self, arg, /) -> int: ...
@@ -81,15 +83,23 @@ class TkappType:
8183
def loadtk(self) -> None: ...
8284
def mainloop(self, threshold: int = 0, /) -> None: ...
8385
def quit(self) -> None: ...
84-
def record(self, script: str, /): ...
86+
def record(self, script: str, /) -> str: ...
8587
def setvar(self, *ags, **kwargs): ...
8688
if sys.version_info < (3, 11):
8789
@deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.")
8890
def split(self, arg, /): ...
8991

90-
def splitlist(self, arg, /): ...
92+
def splitlist(self, arg, /) -> tuple[Incomplete, ...]: ...
9193
def unsetvar(self, *args, **kwargs): ...
92-
def wantobjects(self, *args, **kwargs): ...
94+
if sys.version_info >= (3, 14):
95+
@overload
96+
def wantobjects(self) -> Literal[0, 1]: ...
97+
else:
98+
@overload
99+
def wantobjects(self) -> bool: ...
100+
101+
@overload
102+
def wantobjects(self, wantobjects: Literal[0, 1] | bool, /) -> None: ...
93103
def willdispatch(self) -> None: ...
94104
if sys.version_info >= (3, 12):
95105
def gettrace(self, /) -> _TkinterTraceFunc | None: ...
@@ -112,7 +122,7 @@ TK_VERSION: Final[str]
112122

113123
@final
114124
class TkttType:
115-
def deletetimerhandler(self): ...
125+
def deletetimerhandler(self) -> None: ...
116126

117127
if sys.version_info >= (3, 13):
118128
def create(
@@ -125,7 +135,7 @@ if sys.version_info >= (3, 13):
125135
sync: bool = False,
126136
use: str | None = None,
127137
/,
128-
): ...
138+
) -> TkappType: ...
129139

130140
else:
131141
def create(
@@ -138,7 +148,7 @@ else:
138148
sync: bool = False,
139149
use: str | None = None,
140150
/,
141-
): ...
151+
) -> TkappType: ...
142152

143153
def getbusywaitinterval() -> int: ...
144154
def setbusywaitinterval(new_val: int, /) -> None: ...

0 commit comments

Comments
 (0)