Skip to content

Commit 11f945b

Browse files
Sync typeshed (#21232)
1 parent 16823a1 commit 11f945b

34 files changed

Lines changed: 246 additions & 107 deletions
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
From 7f38b86464d59188a87ff8c9913c257e788a2f0b Mon Sep 17 00:00:00 2001
2+
From: hauntsaninja <hauntsaninja@gmail.com>
3+
Date: Wed, 6 May 2026 19:49:41 -0700
4+
Subject: [PATCH] Revert operator changes
5+
6+
---
7+
mypy/typeshed/stdlib/_operator.pyi | 51 ++++++++----------------------
8+
1 file changed, 14 insertions(+), 37 deletions(-)
9+
10+
diff --git a/mypy/typeshed/stdlib/_operator.pyi b/mypy/typeshed/stdlib/_operator.pyi
11+
index e7d85f811..8c705065b 100644
12+
--- a/mypy/typeshed/stdlib/_operator.pyi
13+
+++ b/mypy/typeshed/stdlib/_operator.pyi
14+
@@ -1,15 +1,5 @@
15+
import sys
16+
-from _typeshed import (
17+
- SupportsAdd,
18+
- SupportsGetItem,
19+
- SupportsMod,
20+
- SupportsMul,
21+
- SupportsRAdd,
22+
- SupportsRMod,
23+
- SupportsRMul,
24+
- SupportsRSub,
25+
- SupportsSub,
26+
-)
27+
+from _typeshed import SupportsGetItem
28+
from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence
29+
from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller
30+
from typing import Any, AnyStr, Protocol, SupportsAbs, SupportsIndex, TypeVar, overload, type_check_only
31+
@@ -18,7 +8,6 @@ from typing_extensions import ParamSpec, TypeAlias, TypeIs
32+
_R = TypeVar("_R")
33+
_T = TypeVar("_T")
34+
_T_co = TypeVar("_T_co", covariant=True)
35+
-_T_contra = TypeVar("_T_contra", contravariant=True)
36+
_K = TypeVar("_K")
37+
_V = TypeVar("_V")
38+
_P = ParamSpec("_P")
39+
@@ -69,36 +58,24 @@ def truth(a: object, /) -> bool: ...
40+
def is_(a: object, b: object, /) -> bool: ...
41+
def is_not(a: object, b: object, /) -> bool: ...
42+
def abs(a: SupportsAbs[_T], /) -> _T: ...
43+
-@overload
44+
-def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
45+
-@overload
46+
-def add(a: _T_contra, b: SupportsRAdd[_T_contra, _T_co], /) -> _T_co: ...
47+
-def and_(a, b, /): ...
48+
-def floordiv(a, b, /): ...
49+
+def add(a: Any, b: Any, /) -> Any: ...
50+
+def and_(a: Any, b: Any, /) -> Any: ...
51+
+def floordiv(a: Any, b: Any, /) -> Any: ...
52+
def index(a: SupportsIndex, /) -> int: ...
53+
def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ...
54+
def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ...
55+
-def lshift(a, b, /): ...
56+
-@overload
57+
-def mod(a: SupportsMod[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
58+
-@overload
59+
-def mod(a: _T_contra, b: SupportsRMod[_T_contra, _T_co], /) -> _T_co: ...
60+
-@overload
61+
-def mul(a: SupportsMul[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
62+
-@overload
63+
-def mul(a: _T_contra, b: SupportsRMul[_T_contra, _T_co], /) -> _T_co: ...
64+
-def matmul(a, b, /): ...
65+
+def lshift(a: Any, b: Any, /) -> Any: ...
66+
+def mod(a: Any, b: Any, /) -> Any: ...
67+
+def mul(a: Any, b: Any, /) -> Any: ...
68+
+def matmul(a: Any, b: Any, /) -> Any: ...
69+
def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ...
70+
-def or_(a, b, /): ...
71+
+def or_(a: Any, b: Any, /) -> Any: ...
72+
def pos(a: _SupportsPos[_T_co], /) -> _T_co: ...
73+
-def pow(a, b, /): ...
74+
-def rshift(a, b, /): ...
75+
-@overload
76+
-def sub(a: SupportsSub[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
77+
-@overload
78+
-def sub(a: _T_contra, b: SupportsRSub[_T_contra, _T_co], /) -> _T_co: ...
79+
-def truediv(a, b, /): ...
80+
-def xor(a, b, /): ...
81+
+def pow(a: Any, b: Any, /) -> Any: ...
82+
+def rshift(a: Any, b: Any, /) -> Any: ...
83+
+def sub(a: Any, b: Any, /) -> Any: ...
84+
+def truediv(a: Any, b: Any, /) -> Any: ...
85+
+def xor(a: Any, b: Any, /) -> Any: ...
86+
def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ...
87+
def contains(a: Container[object], b: object, /) -> bool: ...
88+
def countOf(a: Iterable[object], b: object, /) -> int: ...
89+
--
90+
2.53.0
91+

mypy/typeshed/stdlib/_codecs.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def ascii_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[st
7777
def ascii_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
7878
def charmap_decode(data: ReadableBuffer, errors: str | None = None, mapping: _CharMap | None = None, /) -> tuple[str, int]: ...
7979
def charmap_encode(str: str, errors: str | None = None, mapping: _CharMap | None = None, /) -> tuple[bytes, int]: ...
80-
def escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
80+
81+
# Docs say this accepts a bytes-like object, but in practice it also accepts str.
82+
def escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[bytes, int]: ...
8183
def escape_encode(data: bytes, errors: str | None = None, /) -> tuple[bytes, int]: ...
8284
def latin_1_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
8385
def latin_1_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...

mypy/typeshed/stdlib/_io.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from types import TracebackType
99
from typing import IO, Any, BinaryIO, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload, type_check_only
1010
from typing_extensions import Self, disjoint_base
1111

12-
_T = TypeVar("_T")
12+
_S = TypeVar("_S", bound=str)
1313

1414
if sys.version_info >= (3, 14):
1515
DEFAULT_BUFFER_SIZE: Final = 131072
@@ -298,4 +298,4 @@ if sys.version_info >= (3, 10):
298298
@overload
299299
def text_encoding(encoding: None, stacklevel: int = 2, /) -> Literal["locale", "utf-8"]: ...
300300
@overload
301-
def text_encoding(encoding: _T, stacklevel: int = 2, /) -> _T: ...
301+
def text_encoding(encoding: _S, stacklevel: int = 2, /) -> _S: ...

mypy/typeshed/stdlib/_operator.pyi

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,20 @@ def setitem(a: MutableSequence[_T], b: slice[int | None], c: Sequence[_T], /) ->
9797
@overload
9898
def setitem(a: MutableMapping[_K, _V], b: _K, c: _V, /) -> None: ...
9999
def length_hint(obj: object, default: int = 0, /) -> int: ...
100-
def iadd(a: Any, b: Any, /) -> Any: ...
101-
def iand(a: Any, b: Any, /) -> Any: ...
102-
def iconcat(a: Any, b: Any, /) -> Any: ...
103-
def ifloordiv(a: Any, b: Any, /) -> Any: ...
104-
def ilshift(a: Any, b: Any, /) -> Any: ...
105-
def imod(a: Any, b: Any, /) -> Any: ...
106-
def imul(a: Any, b: Any, /) -> Any: ...
107-
def imatmul(a: Any, b: Any, /) -> Any: ...
108-
def ior(a: Any, b: Any, /) -> Any: ...
109-
def ipow(a: Any, b: Any, /) -> Any: ...
110-
def irshift(a: Any, b: Any, /) -> Any: ...
111-
def isub(a: Any, b: Any, /) -> Any: ...
112-
def itruediv(a: Any, b: Any, /) -> Any: ...
113-
def ixor(a: Any, b: Any, /) -> Any: ...
100+
def iadd(a, b, /): ...
101+
def iand(a, b, /): ...
102+
def iconcat(a, b, /): ...
103+
def ifloordiv(a, b, /): ...
104+
def ilshift(a, b, /): ...
105+
def imod(a, b, /): ...
106+
def imul(a, b, /): ...
107+
def imatmul(a, b, /): ...
108+
def ior(a, b, /): ...
109+
def ipow(a, b, /): ...
110+
def irshift(a, b, /): ...
111+
def isub(a, b, /): ...
112+
def itruediv(a, b, /): ...
113+
def ixor(a, b, /): ...
114114

115115
if sys.version_info >= (3, 11):
116116
def call(obj: Callable[_P, _R], /, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...

mypy/typeshed/stdlib/_socket.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class socket:
741741
def proto(self) -> int: ...
742742
# F811: "Redefinition of unused `timeout`"
743743
@property
744-
def timeout(self) -> float | None: ... # noqa: F811
744+
def timeout(self) -> float | None: ...
745745
if sys.platform == "win32":
746746
def __init__(
747747
self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | bytes | None = None
@@ -838,7 +838,7 @@ def inet_ntop(address_family: int, packed_ip: ReadableBuffer, /) -> str: ...
838838
def getdefaulttimeout() -> float | None: ...
839839

840840
# F811: "Redefinition of unused `timeout`"
841-
def setdefaulttimeout(timeout: float | None, /) -> None: ... # noqa: F811
841+
def setdefaulttimeout(timeout: float | None, /) -> None: ...
842842

843843
if sys.platform != "win32":
844844
def sethostname(name: str, /) -> None: ...

mypy/typeshed/stdlib/_sqlite3.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ if sys.version_info >= (3, 11):
171171
SQLITE_IOERR_VNODE: Final = 6922
172172
SQLITE_IOERR_WRITE: Final = 778
173173
SQLITE_LIMIT_ATTACHED: Final = 7
174-
SQLITE_LIMIT_COLUMN: Final = 22
174+
SQLITE_LIMIT_COLUMN: Final = 2
175175
SQLITE_LIMIT_COMPOUND_SELECT: Final = 4
176176
SQLITE_LIMIT_EXPR_DEPTH: Final = 3
177177
SQLITE_LIMIT_FUNCTION_ARG: Final = 6

mypy/typeshed/stdlib/_ssl.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ CERT_REQUIRED: Final = 2
183183

184184
# verify flags
185185
VERIFY_DEFAULT: Final = 0
186-
VERIFY_CRL_CHECK_LEAF: Final = 0x4
187-
VERIFY_CRL_CHECK_CHAIN: Final = 0x8
186+
VERIFY_CRL_CHECK_LEAF: Final = 0x04
187+
VERIFY_CRL_CHECK_CHAIN: Final = 0x0C
188188
VERIFY_X509_STRICT: Final = 0x20
189189
VERIFY_X509_TRUSTED_FIRST: Final = 0x8000
190190
if sys.version_info >= (3, 10):
@@ -230,7 +230,7 @@ PROTOCOL_TLSv1_1: Final = 4
230230
PROTOCOL_TLSv1_2: Final = 5
231231

232232
# protocol options
233-
OP_ALL: Final = 0x80000050
233+
OP_ALL: Final[int]
234234
OP_NO_SSLv2: Final = 0x0
235235
OP_NO_SSLv3: Final = 0x2000000
236236
OP_NO_TLSv1: Final = 0x4000000

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class SupportsMul(Protocol[_T_contra, _T_co]):
126126
class SupportsRMul(Protocol[_T_contra, _T_co]):
127127
def __rmul__(self, x: _T_contra, /) -> _T_co: ...
128128

129+
class SupportsMod(Protocol[_T_contra, _T_co]):
130+
def __mod__(self, other: _T_contra, /) -> _T_co: ...
131+
132+
class SupportsRMod(Protocol[_T_contra, _T_co]):
133+
def __rmod__(self, other: _T_contra, /) -> _T_co: ...
134+
129135
class SupportsDivMod(Protocol[_T_contra, _T_co]):
130136
def __divmod__(self, other: _T_contra, /) -> _T_co: ...
131137

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class _ActionsContainer:
8585
const: Any = ...,
8686
default: Any = ...,
8787
type: _ActionType = ...,
88-
choices: Iterable[_T] | None = ...,
88+
choices: Iterable[Any] | None = ..., # choices must match the type specified
8989
required: bool = ...,
9090
help: str | None = ...,
9191
metavar: str | tuple[str, ...] | None = ...,
@@ -170,7 +170,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
170170
usage: str | None = None,
171171
description: str | None = None,
172172
epilog: str | None = None,
173-
parents: Sequence[ArgumentParser] = [],
173+
parents: Iterable[ArgumentParser] = [],
174174
formatter_class: _FormatterClass = ...,
175175
prefix_chars: str = "-",
176176
fromfile_prefix_chars: str | None = None,
@@ -190,7 +190,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
190190
usage: str | None = None,
191191
description: str | None = None,
192192
epilog: str | None = None,
193-
parents: Sequence[ArgumentParser] = [],
193+
parents: Iterable[ArgumentParser] = [],
194194
formatter_class: _FormatterClass = ...,
195195
prefix_chars: str = "-",
196196
fromfile_prefix_chars: str | None = None,
@@ -202,9 +202,9 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
202202
) -> None: ...
203203

204204
@overload
205-
def parse_args(self, args: Sequence[str] | None = None, namespace: None = None) -> Namespace: ...
205+
def parse_args(self, args: Iterable[str] | None = None, namespace: None = None) -> Namespace: ...
206206
@overload
207-
def parse_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
207+
def parse_args(self, args: Iterable[str] | None, namespace: _N) -> _N: ...
208208
@overload
209209
def parse_args(self, *, namespace: _N) -> _N: ...
210210
@overload
@@ -241,26 +241,26 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
241241
def format_usage(self) -> str: ...
242242
def format_help(self) -> str: ...
243243
@overload
244-
def parse_known_args(self, args: Sequence[str] | None = None, namespace: None = None) -> tuple[Namespace, list[str]]: ...
244+
def parse_known_args(self, args: Iterable[str] | None = None, namespace: None = None) -> tuple[Namespace, list[str]]: ...
245245
@overload
246-
def parse_known_args(self, args: Sequence[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
246+
def parse_known_args(self, args: Iterable[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
247247
@overload
248248
def parse_known_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ...
249249
def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ...
250250
def exit(self, status: int = 0, message: str | None = None) -> NoReturn: ...
251251
def error(self, message: str) -> NoReturn: ...
252252
@overload
253-
def parse_intermixed_args(self, args: Sequence[str] | None = None, namespace: None = None) -> Namespace: ...
253+
def parse_intermixed_args(self, args: Iterable[str] | None = None, namespace: None = None) -> Namespace: ...
254254
@overload
255-
def parse_intermixed_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
255+
def parse_intermixed_args(self, args: Iterable[str] | None, namespace: _N) -> _N: ...
256256
@overload
257257
def parse_intermixed_args(self, *, namespace: _N) -> _N: ...
258258
@overload
259259
def parse_known_intermixed_args(
260-
self, args: Sequence[str] | None = None, namespace: None = None
260+
self, args: Iterable[str] | None = None, namespace: None = None
261261
) -> tuple[Namespace, list[str]]: ...
262262
@overload
263-
def parse_known_intermixed_args(self, args: Sequence[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
263+
def parse_known_intermixed_args(self, args: Iterable[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
264264
@overload
265265
def parse_known_intermixed_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ...
266266
# undocumented
@@ -346,7 +346,7 @@ class HelpFormatter:
346346
def _metavar_formatter(self, action: Action, default_metavar: str) -> Callable[[int], tuple[str, ...]]: ...
347347
def _format_args(self, action: Action, default_metavar: str) -> str: ...
348348
def _expand_help(self, action: Action) -> str: ...
349-
def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ...
349+
def _iter_indented_subactions(self, action: Action) -> Generator[Action]: ...
350350
def _split_lines(self, text: str, width: int) -> list[str]: ...
351351
def _fill_text(self, text: str, width: int, indent: str) -> str: ...
352352
def _get_help_string(self, action: Action) -> str | None: ...
@@ -785,13 +785,13 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
785785
*,
786786
deprecated: bool = False,
787787
help: str | None = ...,
788-
aliases: Sequence[str] = ...,
788+
aliases: Iterable[str] = ...,
789789
# Kwargs from ArgumentParser constructor
790790
prog: str | None = ...,
791791
usage: str | None = ...,
792792
description: str | None = ...,
793793
epilog: str | None = ...,
794-
parents: Sequence[_ArgumentParserT] = ...,
794+
parents: Iterable[_ArgumentParserT] = ...,
795795
formatter_class: _FormatterClass = ...,
796796
prefix_chars: str = ...,
797797
fromfile_prefix_chars: str | None = ...,
@@ -811,13 +811,13 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
811811
*,
812812
deprecated: bool = False,
813813
help: str | None = ...,
814-
aliases: Sequence[str] = ...,
814+
aliases: Iterable[str] = ...,
815815
# Kwargs from ArgumentParser constructor
816816
prog: str | None = ...,
817817
usage: str | None = ...,
818818
description: str | None = ...,
819819
epilog: str | None = ...,
820-
parents: Sequence[_ArgumentParserT] = ...,
820+
parents: Iterable[_ArgumentParserT] = ...,
821821
formatter_class: _FormatterClass = ...,
822822
prefix_chars: str = ...,
823823
fromfile_prefix_chars: str | None = ...,
@@ -834,13 +834,13 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
834834
name: str,
835835
*,
836836
help: str | None = ...,
837-
aliases: Sequence[str] = ...,
837+
aliases: Iterable[str] = ...,
838838
# Kwargs from ArgumentParser constructor
839839
prog: str | None = ...,
840840
usage: str | None = ...,
841841
description: str | None = ...,
842842
epilog: str | None = ...,
843-
parents: Sequence[_ArgumentParserT] = ...,
843+
parents: Iterable[_ArgumentParserT] = ...,
844844
formatter_class: _FormatterClass = ...,
845845
prefix_chars: str = ...,
846846
fromfile_prefix_chars: str | None = ...,

mypy/typeshed/stdlib/codecs.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ def open(
196196
filename: str, mode: str = "r", encoding: str | None = None, errors: str = "strict", buffering: int = -1
197197
) -> StreamReaderWriter: ...
198198
def EncodedFile(file: _Stream, data_encoding: str, file_encoding: str | None = None, errors: str = "strict") -> StreamRecoder: ...
199-
def iterencode(iterator: Iterable[str], encoding: str, errors: str = "strict") -> Generator[bytes, None, None]: ...
200-
def iterdecode(iterator: Iterable[bytes], encoding: str, errors: str = "strict") -> Generator[str, None, None]: ...
199+
def iterencode(iterator: Iterable[str], encoding: str, errors: str = "strict") -> Generator[bytes]: ...
200+
def iterdecode(iterator: Iterable[bytes], encoding: str, errors: str = "strict") -> Generator[str]: ...
201201

202202
BOM: Final[Literal[b"\xff\xfe", b"\xfe\xff"]] # depends on `sys.byteorder`
203203
BOM_BE: Final = b"\xfe\xff"

0 commit comments

Comments
 (0)