Skip to content

Commit 5004eae

Browse files
cdce8phauntsaninjailevkivskyiAlexWaygood
authored
Sync typeshed (#21507)
Source commit: python/typeshed@6164242 --------- Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com> Co-authored-by: hauntsaninja <hauntsaninja@gmail.com> Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
1 parent e15a6d5 commit 5004eae

356 files changed

Lines changed: 6668 additions & 5397 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,86 @@
1-
From 5c922a2484f2e18c7f901e62bb499b6414cf1090 Mon Sep 17 00:00:00 2001
1+
From 8985351bf6f917db1a7b15ffed95ec2357d9819d Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
3-
Date: Wed, 18 Feb 2026 13:11:02 +0100
3+
Date: Mon, 18 May 2026 17:33:09 +0200
44
Subject: [PATCH] Adjust stubs to fix mypy lookup error due to circular
55
dependencies in stubs
66

77
---
8-
mypy/typeshed/stdlib/time.pyi | 6 +++---
9-
1 file changed, 3 insertions(+), 3 deletions(-)
8+
mypy/typeshed/stdlib/__future__.pyi | 2 +-
9+
mypy/typeshed/stdlib/dis.pyi | 4 ++--
10+
mypy/typeshed/stdlib/inspect.pyi | 4 ++--
11+
mypy/typeshed/stdlib/itertools.pyi | 2 +-
12+
mypy/typeshed/stdlib/time.pyi | 6 +++---
13+
5 files changed, 9 insertions(+), 9 deletions(-)
1014

15+
diff --git a/mypy/typeshed/stdlib/__future__.pyi b/mypy/typeshed/stdlib/__future__.pyi
16+
index aa445d22b..a90cf1edd 100644
17+
--- a/mypy/typeshed/stdlib/__future__.pyi
18+
+++ b/mypy/typeshed/stdlib/__future__.pyi
19+
@@ -1,4 +1,4 @@
20+
-from typing import TypeAlias
21+
+from typing_extensions import TypeAlias
22+
23+
_VersionInfo: TypeAlias = tuple[int, int, int, str, int]
24+
25+
diff --git a/mypy/typeshed/stdlib/dis.pyi b/mypy/typeshed/stdlib/dis.pyi
26+
index 984f932e3..0ad928934 100644
27+
--- a/mypy/typeshed/stdlib/dis.pyi
28+
+++ b/mypy/typeshed/stdlib/dis.pyi
29+
@@ -2,7 +2,7 @@ import sys
30+
import types
31+
from collections.abc import Callable, Iterator
32+
from opcode import * # `dis` re-exports it as a part of public API
33+
-from typing import IO, Any, Final, NamedTuple, TypeAlias, overload
34+
+from typing import IO, Any, Final, NamedTuple, overload
35+
from typing_extensions import Self, deprecated, disjoint_base
36+
37+
__all__ = [
38+
@@ -41,7 +41,7 @@ else:
39+
40+
# Strictly this should not have to include Callable, but mypy doesn't use FunctionType
41+
# for functions (python/mypy#3171)
42+
-_HaveCodeType: TypeAlias = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any]
43+
+_HaveCodeType = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any]
44+
45+
if sys.version_info >= (3, 11):
46+
class Positions(NamedTuple):
47+
diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi
48+
index cc39a7c9f..0ca4cff75 100644
49+
--- a/mypy/typeshed/stdlib/inspect.pyi
50+
+++ b/mypy/typeshed/stdlib/inspect.pyi
51+
@@ -196,8 +196,8 @@ if sys.version_info >= (3, 14):
52+
53+
modulesbyfile: dict[str, Any]
54+
55+
-_GetMembersPredicateTypeGuard: TypeAlias = Callable[[Any], TypeGuard[_T]]
56+
-_GetMembersPredicateTypeIs: TypeAlias = Callable[[Any], TypeIs[_T]]
57+
+_GetMembersPredicateTypeGuard = Callable[[Any], TypeGuard[_T]]
58+
+_GetMembersPredicateTypeIs = Callable[[Any], TypeIs[_T]]
59+
_GetMembersPredicate: TypeAlias = Callable[[Any], bool]
60+
_GetMembersReturn: TypeAlias = list[tuple[str, _T]]
61+
62+
diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi
63+
index d26a4e1da..60e79bc2e 100644
64+
--- a/mypy/typeshed/stdlib/itertools.pyi
65+
+++ b/mypy/typeshed/stdlib/itertools.pyi
66+
@@ -23,7 +23,7 @@ _T10 = TypeVar("_T10")
67+
68+
_Step: TypeAlias = SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex
69+
70+
-_Predicate: TypeAlias = Callable[[_T], object]
71+
+_Predicate = Callable[[_T], object]
72+
73+
# Technically count can take anything that implements a number protocol and has an add method
74+
# but we can't enforce the add method
1175
diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi
12-
index 64a009318..d0853792b 100644
76+
index ac53089b8..9b5344b32 100644
1377
--- a/mypy/typeshed/stdlib/time.pyi
1478
+++ b/mypy/typeshed/stdlib/time.pyi
15-
@@ -1,16 +1,16 @@
79+
@@ -1,15 +1,15 @@
1680
import sys
1781
from _typeshed import structseq
18-
-from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, final, type_check_only
19-
+from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, Union, final, type_check_only
20-
from typing_extensions import TypeAlias
82+
-from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, final, type_check_only
83+
+from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, Union, final, type_check_only
2184

2285
_TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int]
2386

@@ -33,5 +96,5 @@ index 64a009318..d0853792b 100644
3396
altzone: int
3497
daylight: int
3598
--
36-
2.53.0
99+
2.54.0
37100

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From b6d495c10e79fb56ff64f8fb90c87894090f9cbe Mon Sep 17 00:00:00 2001
1+
From 3fa6658041d3ccd7f2a4bd725e21fa9768bf6ebc 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,16 +8,16 @@ 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 ae99eb036..c87b8f4fc 100644
11+
index 22d330a08..fa22f842d 100644
1212
--- a/mypy/typeshed/stdlib/argparse.pyi
1313
+++ b/mypy/typeshed/stdlib/argparse.pyi
1414
@@ -2,7 +2,7 @@ import sys
1515
from _typeshed import SupportsWrite, sentinel
1616
from collections.abc import Callable, Generator, Iterable, Sequence
1717
from re import Pattern
18-
-from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload, type_check_only
19-
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload, type_check_only
20-
from typing_extensions import Self, TypeAlias, deprecated
18+
-from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only
19+
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only
20+
from typing_extensions import Self, deprecated
2121

2222
__all__ = [
2323
@@ -36,7 +36,9 @@ ONE_OR_MORE: Final = "+"
@@ -41,5 +41,5 @@ index ae99eb036..c87b8f4fc 100644
4141
default: Any = ...,
4242
type: _ActionType = ...,
4343
--
44-
2.52.0
44+
2.54.0
4545

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,94 @@
1-
From b3021cdc4b4c2cf547c5bc2d1d21a5a00ffea001 Mon Sep 17 00:00:00 2001
1+
From 83cf9b2dcc569149510c3a9118b9a7dc44144232 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)
55

66
---
7-
mypy/typeshed/stdlib/builtins.pyi | 98 -------------------------------
8-
1 file changed, 98 deletions(-)
7+
mypy/typeshed/stdlib/builtins.pyi | 127 +-----------------------------
8+
1 file changed, 1 insertion(+), 126 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11-
index efc51fe25..8600a372b 100644
11+
index 0fe6d9a69..1808e28e2 100644
1212
--- a/mypy/typeshed/stdlib/builtins.pyi
1313
+++ b/mypy/typeshed/stdlib/builtins.pyi
14-
@@ -64,7 +64,6 @@ from typing import ( # noqa: Y022,UP035
15-
from typing_extensions import ( # noqa: Y023
16-
Concatenate,
17-
Literal,
18-
- LiteralString,
19-
ParamSpec,
20-
Self,
21-
TypeAlias,
22-
@@ -482,31 +481,16 @@ class str(Sequence[str]):
14+
@@ -65,7 +65,7 @@ from typing import ( # noqa: Y022,UP035
15+
)
16+
17+
# we can't import `Literal` from typing or mypy crashes: see #11247
18+
-from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035
19+
+from typing_extensions import Literal, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035
20+
21+
if sys.version_info >= (3, 14):
22+
from _typeshed import AnnotateFunc
23+
@@ -489,20 +489,8 @@ class str(Sequence[str]):
2324
def __new__(cls, object: object = "") -> Self: ...
2425
@overload
2526
def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ...
27+
-
2628
- @overload
2729
- def capitalize(self: LiteralString) -> LiteralString: ...
2830
- @overload
2931
def capitalize(self) -> str: ... # type: ignore[misc]
32+
-
3033
- @overload
3134
- def casefold(self: LiteralString) -> LiteralString: ...
3235
- @overload
3336
def casefold(self) -> str: ... # type: ignore[misc]
37+
-
3438
- @overload
3539
- def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
3640
- @overload
3741
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
42+
3843
def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
39-
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
44+
@@ -510,17 +498,9 @@ class str(Sequence[str]):
4045
def endswith(
4146
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
4247
) -> bool: ...
48+
-
4349
- @overload
4450
- def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
4551
- @overload
4652
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
53+
4754
def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
55+
-
4856
- @overload
4957
- def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
5058
- @overload
5159
def format(self, *args: object, **kwargs: object) -> str: ...
60+
5261
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
53-
def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
54-
@@ -522,98 +506,34 @@ class str(Sequence[str]):
62+
@@ -537,119 +517,38 @@ class str(Sequence[str]):
5563
def isspace(self) -> bool: ...
5664
def istitle(self) -> bool: ...
5765
def isupper(self) -> bool: ...
66+
-
5867
- @overload
5968
- def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
6069
- @overload
6170
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
71+
-
6272
- @overload
6373
- def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
6474
- @overload
6575
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
76+
-
6677
- @overload
6778
- def lower(self: LiteralString) -> LiteralString: ...
6879
- @overload
6980
def lower(self) -> str: ... # type: ignore[misc]
81+
-
7082
- @overload
7183
- def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
7284
- @overload
7385
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
86+
-
7487
- @overload
7588
- def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
7689
- @overload
7790
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
91+
7892
if sys.version_info >= (3, 13):
7993
- @overload
8094
- def replace(
@@ -94,102 +108,127 @@ index efc51fe25..8600a372b 100644
94108
- def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
95109
- @overload
96110
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
111+
-
97112
- @overload
98113
- def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
99114
- @overload
100115
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
116+
101117
def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
102118
def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
119+
-
103120
- @overload
104121
- def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
105122
- @overload
106123
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
124+
-
107125
- @overload
108126
- def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
109127
- @overload
110128
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
129+
-
111130
- @overload
112131
- def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
113132
- @overload
114133
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
134+
-
115135
- @overload
116136
- def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
117137
- @overload
118138
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
139+
-
119140
- @overload
120141
- def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
121142
- @overload
122143
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
144+
-
123145
- @overload
124146
- def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
125147
- @overload
126148
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
149+
127150
def startswith(
128151
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
129152
) -> bool: ...
153+
-
130154
- @overload
131155
- def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
132156
- @overload
133157
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
158+
-
134159
- @overload
135160
- def swapcase(self: LiteralString) -> LiteralString: ...
136161
- @overload
137162
def swapcase(self) -> str: ... # type: ignore[misc]
163+
-
138164
- @overload
139165
- def title(self: LiteralString) -> LiteralString: ...
140166
- @overload
141167
def title(self) -> str: ... # type: ignore[misc]
168+
142169
def translate(self, table: _TranslateTable, /) -> str: ...
170+
-
143171
- @overload
144172
- def upper(self: LiteralString) -> LiteralString: ...
145173
- @overload
146174
def upper(self) -> str: ... # type: ignore[misc]
175+
-
147176
- @overload
148177
- def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
149178
- @overload
150179
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
151-
@staticmethod
152-
@overload
153-
@@ -624,39 +544,21 @@ class str(Sequence[str]):
180+
181+
if sys.version_info >= (3, 15):
182+
@@ -677,49 +576,25 @@ class str(Sequence[str]):
154183
@staticmethod
155184
@overload
156185
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
186+
-
157187
- @overload
158188
- def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
159189
- @overload
160190
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
191+
161192
# Incompatible with Sequence.__contains__
162193
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
163194
def __eq__(self, value: object, /) -> bool: ...
164195
def __ge__(self, value: str, /) -> bool: ...
196+
-
165197
- @overload
166198
- def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ...
167199
- @overload
168200
def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc]
201+
169202
def __gt__(self, value: str, /) -> bool: ...
170203
def __hash__(self) -> int: ...
204+
-
171205
- @overload
172206
- def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
173207
- @overload
174208
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
209+
175210
def __le__(self, value: str, /) -> bool: ...
176211
def __len__(self) -> int: ...
177212
def __lt__(self, value: str, /) -> bool: ...
213+
-
178214
- @overload
179215
- def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
180216
- @overload
181217
def __mod__(self, value: Any, /) -> str: ...
218+
-
182219
- @overload
183220
- def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
184221
- @overload
185222
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
223+
186224
def __ne__(self, value: object, /) -> bool: ...
225+
-
187226
- @overload
188227
- def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
189228
- @overload
190229
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
230+
191231
def __getnewargs__(self) -> tuple[str]: ...
192-
def __format__(self, format_spec: str, /) -> str: ...
193232
--
194-
2.52.0
233+
2.54.0
195234

0 commit comments

Comments
 (0)