Debian Codegraph @

jedi/third_party/typeshed/stdlib/builtins.pyi

raw symbols SCIP
1 import _ast
2 import _sitebuiltins
3 import _typeshed
4 import sys
5 import types
6 from _collections_abc import dict_items, dict_keys, dict_values
7 from _typeshed import (
8 AnnotationForm,
9 ConvertibleToFloat,
10 ConvertibleToInt,
11 FileDescriptorOrPath,
12 OpenBinaryMode,
13 OpenBinaryModeReading,
14 OpenBinaryModeUpdating,
15 OpenBinaryModeWriting,
16 OpenTextMode,
17 ReadableBuffer,
18 SupportsAdd,
19 SupportsAiter,
20 SupportsAnext,
21 SupportsDivMod,
22 SupportsFlush,
23 SupportsIter,
24 SupportsKeysAndGetItem,
25 SupportsLenAndGetItem,
26 SupportsNext,
27 SupportsRAdd,
28 SupportsRDivMod,
29 SupportsRichComparison,
30 SupportsRichComparisonT,
31 SupportsWrite,
32 )
33 from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
34 from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
35 from os import PathLike
36 from types import CellType, CodeType, GenericAlias, TracebackType
37
38 # mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping}
39 # are imported from collections.abc in builtins.pyi
40 from typing import ( # noqa: Y022,UP035,RUF100
41 IO,
42 Any,
43 BinaryIO,
44 ClassVar,
45 Final,
46 Generic,
47 Mapping,
48 MutableMapping,
49 MutableSequence,
50 Protocol,
51 Sequence,
52 SupportsAbs,
53 SupportsBytes,
54 SupportsComplex,
55 SupportsFloat,
56 SupportsIndex,
57 TypeVar,
58 final,
59 overload,
60 type_check_only,
61 )
62
63 # we can't import `Literal` from typing or mypy crashes: see #11247
64 from typing_extensions import ( # noqa: Y023
65 Concatenate,
66 Literal,
67 LiteralString,
68 ParamSpec,
69 Self,
70 TypeAlias,
71 TypeGuard,
72 TypeIs,
73 TypeVarTuple,
74 deprecated,
75 # disjoint_base,
76 )
77
78 if sys.version_info >= (3, 14):
79 from _typeshed import AnnotateFunc
80
81 _T = TypeVar("_T")
82 _I = TypeVar("_I", default=int)
83 _T_co = TypeVar("_T_co", covariant=True)
84 _T_contra = TypeVar("_T_contra", contravariant=True)
85 _R_co = TypeVar("_R_co", covariant=True)
86 _KT = TypeVar("_KT")
87 _VT = TypeVar("_VT")
88 _S = TypeVar("_S")
89 _T1 = TypeVar("_T1")
90 _T2 = TypeVar("_T2")
91 _T3 = TypeVar("_T3")
92 _T4 = TypeVar("_T4")
93 _T5 = TypeVar("_T5")
94 _SupportsNextT_co = TypeVar("_SupportsNextT_co", bound=SupportsNext[Any], covariant=True)
95 _SupportsAnextT_co = TypeVar("_SupportsAnextT_co", bound=SupportsAnext[Any], covariant=True)
96 _AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
97 _AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
98 _P = ParamSpec("_P")
99
100 # Type variables for slice
101 _StartT_co = TypeVar("_StartT_co", covariant=True, default=Any) # slice -> slice[Any, Any, Any]
102 _StopT_co = TypeVar("_StopT_co", covariant=True, default=_StartT_co) # slice[A] -> slice[A, A, A]
103 # NOTE: step could differ from start and stop, (e.g. datetime/timedelta)l
104 # the default (start|stop) is chosen to cater to the most common case of int/index slices.
105 # FIXME: https://github.com/python/typing/issues/213 (replace step=start|stop with step=start&stop)
106 _StepT_co = TypeVar("_StepT_co", covariant=True, default=_StartT_co | _StopT_co) # slice[A,B] -> slice[A, B, A|B]
107
108 @disjoint_base
109 class object:
110 __doc__: str | None
111 __dict__: dict[str, Any]
112 __module__: str
113 __annotations__: dict[str, Any]
114 @property
115 def __class__(self) -> type[Self]: ...
116 @__class__.setter
117 def __class__(self, type: type[Self], /) -> None: ...
118 def __init__(self) -> None: ...
119 def __new__(cls) -> Self: ...
120 # N.B. `object.__setattr__` and `object.__delattr__` are heavily special-cased by type checkers.
121 # Overriding them in subclasses has different semantics, even if the override has an identical signature.
122 def __setattr__(self, name: str, value: Any, /) -> None: ...
123 def __delattr__(self, name: str, /) -> None: ...
124 def __eq__(self, value: object, /) -> bool: ...
125 def __ne__(self, value: object, /) -> bool: ...
126 def __str__(self) -> str: ... # noqa: Y029
127 def __repr__(self) -> str: ... # noqa: Y029
128 def __hash__(self) -> int: ...
129 def __format__(self, format_spec: str, /) -> str: ...
130 def __getattribute__(self, name: str, /) -> Any: ...
131 def __sizeof__(self) -> int: ...
132 # return type of pickle methods is rather hard to express in the current type system
133 # see #6661 and https://docs.python.org/3/library/pickle.html#object.__reduce__
134 def __reduce__(self) -> str | tuple[Any, ...]: ...
135 def __reduce_ex__(self, protocol: SupportsIndex, /) -> str | tuple[Any, ...]: ...
136 if sys.version_info >= (3, 11):
137 def __getstate__(self) -> object: ...
138
139 def __dir__(self) -> Iterable[str]: ...
140 def __init_subclass__(cls) -> None: ...
141 @classmethod
142 def __subclasshook__(cls, subclass: type, /) -> bool: ...
143
144 @disjoint_base
145 class staticmethod(Generic[_P, _R_co]):
146 @property
147 def __func__(self) -> Callable[_P, _R_co]: ...
148 @property
149 def __isabstractmethod__(self) -> bool: ...
150 def __init__(self, f: Callable[_P, _R_co], /) -> None: ...
151 @overload
152 def __get__(self, instance: None, owner: type, /) -> Callable[_P, _R_co]: ...
153 @overload
154 def __get__(self, instance: _T, owner: type[_T] | None = None, /) -> Callable[_P, _R_co]: ...
155 if sys.version_info >= (3, 10):
156 __name__: str
157 __qualname__: str
158 @property
159 def __wrapped__(self) -> Callable[_P, _R_co]: ...
160 def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ...
161 if sys.version_info >= (3, 14):
162 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
163 __annotate__: AnnotateFunc | None
164
165 @disjoint_base
166 class classmethod(Generic[_T, _P, _R_co]):
167 @property
168 def __func__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ...
169 @property
170 def __isabstractmethod__(self) -> bool: ...
171 def __init__(self, f: Callable[Concatenate[type[_T], _P], _R_co], /) -> None: ...
172 @overload
173 def __get__(self, instance: _T, owner: type[_T] | None = None, /) -> Callable[_P, _R_co]: ...
174 @overload
175 def __get__(self, instance: None, owner: type[_T], /) -> Callable[_P, _R_co]: ...
176 if sys.version_info >= (3, 10):
177 __name__: str
178 __qualname__: str
179 @property
180 def __wrapped__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ...
181 if sys.version_info >= (3, 14):
182 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
183 __annotate__: AnnotateFunc | None
184
185 @disjoint_base
186 class type:
187 # object.__base__ is None. Otherwise, it would be a type.
188 @property
189 def __base__(self) -> type | None: ...
190 __bases__: tuple[type, ...]
191 @property
192 def __basicsize__(self) -> int: ...
193 # type.__dict__ is read-only at runtime, but that can't be expressed currently.
194 # See https://github.com/python/typeshed/issues/11033 for a discussion.
195 __dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment]
196 @property
197 def __dictoffset__(self) -> int: ...
198 @property
199 def __flags__(self) -> int: ...
200 @property
201 def __itemsize__(self) -> int: ...
202 __module__: str
203 @property
204 def __mro__(self) -> tuple[type, ...]: ...
205 __name__: str
206 __qualname__: str
207 @property
208 def __text_signature__(self) -> str | None: ...
209 @property
210 def __weakrefoffset__(self) -> int: ...
211 @overload
212 def __init__(self, o: object, /) -> None: ...
213 @overload
214 def __init__(self, name: str, bases: tuple[type, ...], dict: dict[str, Any], /, **kwds: Any) -> None: ...
215 @overload
216 def __new__(cls, o: object, /) -> type: ...
217 @overload
218 def __new__(
219 cls: type[_typeshed.Self], name: str, bases: tuple[type, ...], namespace: dict[str, Any], /, **kwds: Any
220 ) -> _typeshed.Self: ...
221 def __call__(self, *args: Any, **kwds: Any) -> Any: ...
222 def __subclasses__(self: _typeshed.Self) -> list[_typeshed.Self]: ...
223 # Note: the documentation doesn't specify what the return type is, the standard
224 # implementation seems to be returning a list.
225 def mro(self) -> list[type]: ...
226 def __instancecheck__(self, instance: Any, /) -> bool: ...
227 def __subclasscheck__(self, subclass: type, /) -> bool: ...
228 @classmethod
229 def __prepare__(metacls, name: str, bases: tuple[type, ...], /, **kwds: Any) -> MutableMapping[str, object]: ...
230 if sys.version_info >= (3, 10):
231 # `int | str` produces an instance of `UnionType`, but `int | int` produces an instance of `type`,
232 # and `abc.ABC | abc.ABC` produces an instance of `abc.ABCMeta`.
233 def __or__(self: _typeshed.Self, value: Any, /) -> types.UnionType | _typeshed.Self: ...
234 def __ror__(self: _typeshed.Self, value: Any, /) -> types.UnionType | _typeshed.Self: ...
235 if sys.version_info >= (3, 12):
236 __type_params__: tuple[TypeVar | ParamSpec | TypeVarTuple, ...]
237 __annotations__: dict[str, AnnotationForm]
238 if sys.version_info >= (3, 14):
239 __annotate__: AnnotateFunc | None
240
241 @disjoint_base
242 class super:
243 @overload
244 def __init__(self, t: Any, obj: Any, /) -> None: ...
245 @overload
246 def __init__(self, t: Any, /) -> None: ...
247 @overload
248 def __init__(self) -> None: ...
249
250 _PositiveInteger: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
251 _NegativeInteger: TypeAlias = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20]
252 _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed
253
254 @disjoint_base
255 class int:
256 @overload
257 def __new__(cls, x: ConvertibleToInt = 0, /) -> Self: ...
258 @overload
259 def __new__(cls, x: str | bytes | bytearray, /, base: SupportsIndex) -> Self: ...
260 def as_integer_ratio(self) -> tuple[int, Literal[1]]: ...
261 @property
262 def real(self) -> int: ...
263 @property
264 def imag(self) -> Literal[0]: ...
265 @property
266 def numerator(self) -> int: ...
267 @property
268 def denominator(self) -> Literal[1]: ...
269 def conjugate(self) -> int: ...
270 def bit_length(self) -> int: ...
271 if sys.version_info >= (3, 10):
272 def bit_count(self) -> int: ...
273
274 if sys.version_info >= (3, 11):
275 def to_bytes(
276 self, length: SupportsIndex = 1, byteorder: Literal["little", "big"] = "big", *, signed: bool = False
277 ) -> bytes: ...
278 @classmethod
279 def from_bytes(
280 cls,
281 bytes: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer,
282 byteorder: Literal["little", "big"] = "big",
283 *,
284 signed: bool = False,
285 ) -> Self: ...
286 else:
287 def to_bytes(self, length: SupportsIndex, byteorder: Literal["little", "big"], *, signed: bool = False) -> bytes: ...
288 @classmethod
289 def from_bytes(
290 cls,
291 bytes: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer,
292 byteorder: Literal["little", "big"],
293 *,
294 signed: bool = False,
295 ) -> Self: ...
296
297 if sys.version_info >= (3, 12):
298 def is_integer(self) -> Literal[True]: ...
299
300 def __add__(self, value: int, /) -> int: ...
301 def __sub__(self, value: int, /) -> int: ...
302 def __mul__(self, value: int, /) -> int: ...
303 def __floordiv__(self, value: int, /) -> int: ...
304 def __truediv__(self, value: int, /) -> float: ...
305 def __mod__(self, value: int, /) -> int: ...
306 def __divmod__(self, value: int, /) -> tuple[int, int]: ...
307 def __radd__(self, value: int, /) -> int: ...
308 def __rsub__(self, value: int, /) -> int: ...
309 def __rmul__(self, value: int, /) -> int: ...
310 def __rfloordiv__(self, value: int, /) -> int: ...
311 def __rtruediv__(self, value: int, /) -> float: ...
312 def __rmod__(self, value: int, /) -> int: ...
313 def __rdivmod__(self, value: int, /) -> tuple[int, int]: ...
314 @overload
315 def __pow__(self, x: Literal[0], /) -> Literal[1]: ...
316 @overload
317 def __pow__(self, value: Literal[0], mod: None, /) -> Literal[1]: ...
318 @overload
319 def __pow__(self, value: _PositiveInteger, mod: None = None, /) -> int: ...
320 @overload
321 def __pow__(self, value: _NegativeInteger, mod: None = None, /) -> float: ...
322 # positive __value -> int; negative __value -> float
323 # return type must be Any as `int | float` causes too many false-positive errors
324 @overload
325 def __pow__(self, value: int, mod: None = None, /) -> Any: ...
326 @overload
327 def __pow__(self, value: int, mod: int, /) -> int: ...
328 def __rpow__(self, value: int, mod: int | None = None, /) -> Any: ...
329 def __and__(self, value: int, /) -> int: ...
330 def __or__(self, value: int, /) -> int: ...
331 def __xor__(self, value: int, /) -> int: ...
332 def __lshift__(self, value: int, /) -> int: ...
333 def __rshift__(self, value: int, /) -> int: ...
334 def __rand__(self, value: int, /) -> int: ...
335 def __ror__(self, value: int, /) -> int: ...
336 def __rxor__(self, value: int, /) -> int: ...
337 def __rlshift__(self, value: int, /) -> int: ...
338 def __rrshift__(self, value: int, /) -> int: ...
339 def __neg__(self) -> int: ...
340 def __pos__(self) -> int: ...
341 def __invert__(self) -> int: ...
342 def __trunc__(self) -> int: ...
343 def __ceil__(self) -> int: ...
344 def __floor__(self) -> int: ...
345 if sys.version_info >= (3, 14):
346 def __round__(self, ndigits: SupportsIndex | None = None, /) -> int: ...
347 else:
348 def __round__(self, ndigits: SupportsIndex = ..., /) -> int: ...
349
350 def __getnewargs__(self) -> tuple[int]: ...
351 def __eq__(self, value: object, /) -> bool: ...
352 def __ne__(self, value: object, /) -> bool: ...
353 def __lt__(self, value: int, /) -> bool: ...
354 def __le__(self, value: int, /) -> bool: ...
355 def __gt__(self, value: int, /) -> bool: ...
356 def __ge__(self, value: int, /) -> bool: ...
357 def __float__(self) -> float: ...
358 def __int__(self) -> int: ...
359 def __abs__(self) -> int: ...
360 def __hash__(self) -> int: ...
361 def __bool__(self) -> bool: ...
362 def __index__(self) -> int: ...
363 def __format__(self, format_spec: str, /) -> str: ...
364
365 @disjoint_base
366 class float:
367 def __new__(cls, x: ConvertibleToFloat = 0, /) -> Self: ...
368 def as_integer_ratio(self) -> tuple[int, int]: ...
369 def hex(self) -> str: ...
370 def is_integer(self) -> bool: ...
371 @classmethod
372 def fromhex(cls, string: str, /) -> Self: ...
373 @property
374 def real(self) -> float: ...
375 @property
376 def imag(self) -> float: ...
377 def conjugate(self) -> float: ...
378 def __add__(self, value: float, /) -> float: ...
379 def __sub__(self, value: float, /) -> float: ...
380 def __mul__(self, value: float, /) -> float: ...
381 def __floordiv__(self, value: float, /) -> float: ...
382 def __truediv__(self, value: float, /) -> float: ...
383 def __mod__(self, value: float, /) -> float: ...
384 def __divmod__(self, value: float, /) -> tuple[float, float]: ...
385 @overload
386 def __pow__(self, value: int, mod: None = None, /) -> float: ...
387 # positive __value -> float; negative __value -> complex
388 # return type must be Any as `float | complex` causes too many false-positive errors
389 @overload
390 def __pow__(self, value: float, mod: None = None, /) -> Any: ...
391 def __radd__(self, value: float, /) -> float: ...
392 def __rsub__(self, value: float, /) -> float: ...
393 def __rmul__(self, value: float, /) -> float: ...
394 def __rfloordiv__(self, value: float, /) -> float: ...
395 def __rtruediv__(self, value: float, /) -> float: ...
396 def __rmod__(self, value: float, /) -> float: ...
397 def __rdivmod__(self, value: float, /) -> tuple[float, float]: ...
398 @overload
399 def __rpow__(self, value: _PositiveInteger, mod: None = None, /) -> float: ...
400 @overload
401 def __rpow__(self, value: _NegativeInteger, mod: None = None, /) -> complex: ...
402 # Returning `complex` for the general case gives too many false-positive errors.
403 @overload
404 def __rpow__(self, value: float, mod: None = None, /) -> Any: ...
405 def __getnewargs__(self) -> tuple[float]: ...
406 def __trunc__(self) -> int: ...
407 def __ceil__(self) -> int: ...
408 def __floor__(self) -> int: ...
409 @overload
410 def __round__(self, ndigits: None = None, /) -> int: ...
411 @overload
412 def __round__(self, ndigits: SupportsIndex, /) -> float: ...
413 def __eq__(self, value: object, /) -> bool: ...
414 def __ne__(self, value: object, /) -> bool: ...
415 def __lt__(self, value: float, /) -> bool: ...
416 def __le__(self, value: float, /) -> bool: ...
417 def __gt__(self, value: float, /) -> bool: ...
418 def __ge__(self, value: float, /) -> bool: ...
419 def __neg__(self) -> float: ...
420 def __pos__(self) -> float: ...
421 def __int__(self) -> int: ...
422 def __float__(self) -> float: ...
423 def __abs__(self) -> float: ...
424 def __hash__(self) -> int: ...
425 def __bool__(self) -> bool: ...
426 def __format__(self, format_spec: str, /) -> str: ...
427 if sys.version_info >= (3, 14):
428 @classmethod
429 def from_number(cls, number: float | SupportsIndex | SupportsFloat, /) -> Self: ...
430
431 @disjoint_base
432 class complex:
433 # Python doesn't currently accept SupportsComplex for the second argument
434 @overload
435 def __new__(
436 cls,
437 real: complex | SupportsComplex | SupportsFloat | SupportsIndex = 0,
438 imag: complex | SupportsFloat | SupportsIndex = 0,
439 ) -> Self: ...
440 @overload
441 def __new__(cls, real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ...
442 @property
443 def real(self) -> float: ...
444 @property
445 def imag(self) -> float: ...
446 def conjugate(self) -> complex: ...
447 def __add__(self, value: complex, /) -> complex: ...
448 def __sub__(self, value: complex, /) -> complex: ...
449 def __mul__(self, value: complex, /) -> complex: ...
450 def __pow__(self, value: complex, mod: None = None, /) -> complex: ...
451 def __truediv__(self, value: complex, /) -> complex: ...
452 def __radd__(self, value: complex, /) -> complex: ...
453 def __rsub__(self, value: complex, /) -> complex: ...
454 def __rmul__(self, value: complex, /) -> complex: ...
455 def __rpow__(self, value: complex, mod: None = None, /) -> complex: ...
456 def __rtruediv__(self, value: complex, /) -> complex: ...
457 def __eq__(self, value: object, /) -> bool: ...
458 def __ne__(self, value: object, /) -> bool: ...
459 def __neg__(self) -> complex: ...
460 def __pos__(self) -> complex: ...
461 def __abs__(self) -> float: ...
462 def __hash__(self) -> int: ...
463 def __bool__(self) -> bool: ...
464 def __format__(self, format_spec: str, /) -> str: ...
465 if sys.version_info >= (3, 11):
466 def __complex__(self) -> complex: ...
467 if sys.version_info >= (3, 14):
468 @classmethod
469 def from_number(cls, number: complex | SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ...
470
471 @type_check_only
472 class _FormatMapMapping(Protocol):
473 def __getitem__(self, key: str, /) -> Any: ...
474
475 @type_check_only
476 class _TranslateTable(Protocol):
477 def __getitem__(self, key: int, /) -> str | int | None: ...
478
479 @disjoint_base
480 class str(Sequence[str]):
481 @overload
482 def __new__(cls, object: object = "") -> Self: ...
483 @overload
484 def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ...
485 @overload
486 def capitalize(self: LiteralString) -> LiteralString: ...
487 @overload
488 def capitalize(self) -> str: ... # type: ignore[misc]
489 @overload
490 def casefold(self: LiteralString) -> LiteralString: ...
491 @overload
492 def casefold(self) -> str: ... # type: ignore[misc]
493 @overload
494 def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
495 @overload
496 def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
497 def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
498 def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
499 def endswith(
500 self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
501 ) -> bool: ...
502 @overload
503 def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
504 @overload
505 def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
506 def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
507 @overload
508 def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
509 @overload
510 def format(self, *args: object, **kwargs: object) -> str: ...
511 def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
512 def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
513 def isalnum(self) -> bool: ...
514 def isalpha(self) -> bool: ...
515 def isascii(self) -> bool: ...
516 def isdecimal(self) -> bool: ...
517 def isdigit(self) -> bool: ...
518 def isidentifier(self) -> bool: ...
519 def islower(self) -> bool: ...
520 def isnumeric(self) -> bool: ...
521 def isprintable(self) -> bool: ...
522 def isspace(self) -> bool: ...
523 def istitle(self) -> bool: ...
524 def isupper(self) -> bool: ...
525 @overload
526 def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
527 @overload
528 def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
529 @overload
530 def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
531 @overload
532 def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
533 @overload
534 def lower(self: LiteralString) -> LiteralString: ...
535 @overload
536 def lower(self) -> str: ... # type: ignore[misc]
537 @overload
538 def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
539 @overload
540 def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
541 @overload
542 def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
543 @overload
544 def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
545 if sys.version_info >= (3, 13):
546 @overload
547 def replace(
548 self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
549 ) -> LiteralString: ...
550 @overload
551 def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
552 else:
553 @overload
554 def replace(
555 self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
556 ) -> LiteralString: ...
557 @overload
558 def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
559
560 @overload
561 def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
562 @overload
563 def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
564 @overload
565 def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
566 @overload
567 def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
568 def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
569 def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
570 @overload
571 def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
572 @overload
573 def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
574 @overload
575 def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
576 @overload
577 def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
578 @overload
579 def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
580 @overload
581 def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
582 @overload
583 def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
584 @overload
585 def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
586 @overload
587 def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
588 @overload
589 def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
590 @overload
591 def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
592 @overload
593 def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
594 def startswith(
595 self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
596 ) -> bool: ...
597 @overload
598 def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
599 @overload
600 def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
601 @overload
602 def swapcase(self: LiteralString) -> LiteralString: ...
603 @overload
604 def swapcase(self) -> str: ... # type: ignore[misc]
605 @overload
606 def title(self: LiteralString) -> LiteralString: ...
607 @overload
608 def title(self) -> str: ... # type: ignore[misc]
609 def translate(self, table: _TranslateTable, /) -> str: ...
610 @overload
611 def upper(self: LiteralString) -> LiteralString: ...
612 @overload
613 def upper(self) -> str: ... # type: ignore[misc]
614 @overload
615 def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
616 @overload
617 def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
618 @staticmethod
619 @overload
620 def maketrans(x: dict[int, _T] | dict[str, _T] | dict[str | int, _T], /) -> dict[int, _T]: ...
621 @staticmethod
622 @overload
623 def maketrans(x: str, y: str, /) -> dict[int, int]: ...
624 @staticmethod
625 @overload
626 def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
627 @overload
628 def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
629 @overload
630 def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
631 # Incompatible with Sequence.__contains__
632 def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
633 def __eq__(self, value: object, /) -> bool: ...
634 def __ge__(self, value: str, /) -> bool: ...
635 @overload
636 def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ...
637 @overload
638 def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc]
639 def __gt__(self, value: str, /) -> bool: ...
640 def __hash__(self) -> int: ...
641 @overload
642 def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
643 @overload
644 def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
645 def __le__(self, value: str, /) -> bool: ...
646 def __len__(self) -> int: ...
647 def __lt__(self, value: str, /) -> bool: ...
648 @overload
649 def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
650 @overload
651 def __mod__(self, value: Any, /) -> str: ...
652 @overload
653 def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
654 @overload
655 def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
656 def __ne__(self, value: object, /) -> bool: ...
657 @overload
658 def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
659 @overload
660 def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
661 def __getnewargs__(self) -> tuple[str]: ...
662 def __format__(self, format_spec: str, /) -> str: ...
663
664 @disjoint_base
665 class bytes(Sequence[int]):
666 @overload
667 def __new__(cls, o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer, /) -> Self: ...
668 @overload
669 def __new__(cls, string: str, /, encoding: str, errors: str = "strict") -> Self: ...
670 @overload
671 def __new__(cls) -> Self: ...
672 def capitalize(self) -> bytes: ...
673 def center(self, width: SupportsIndex, fillchar: bytes = b" ", /) -> bytes: ...
674 def count(
675 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
676 ) -> int: ...
677 def decode(self, encoding: str = "utf-8", errors: str = "strict") -> str: ...
678 def endswith(
679 self,
680 suffix: ReadableBuffer | tuple[ReadableBuffer, ...],
681 start: SupportsIndex | None = None,
682 end: SupportsIndex | None = None,
683 /,
684 ) -> bool: ...
685 def expandtabs(self, tabsize: SupportsIndex = 8) -> bytes: ...
686 def find(
687 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
688 ) -> int: ...
689 def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = 1) -> str: ...
690 def index(
691 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
692 ) -> int: ...
693 def isalnum(self) -> bool: ...
694 def isalpha(self) -> bool: ...
695 def isascii(self) -> bool: ...
696 def isdigit(self) -> bool: ...
697 def islower(self) -> bool: ...
698 def isspace(self) -> bool: ...
699 def istitle(self) -> bool: ...
700 def isupper(self) -> bool: ...
701 def join(self, iterable_of_bytes: Iterable[ReadableBuffer], /) -> bytes: ...
702 def ljust(self, width: SupportsIndex, fillchar: bytes | bytearray = b" ", /) -> bytes: ...
703 def lower(self) -> bytes: ...
704 def lstrip(self, bytes: ReadableBuffer | None = None, /) -> bytes: ...
705 def partition(self, sep: ReadableBuffer, /) -> tuple[bytes, bytes, bytes]: ...
706 def replace(self, old: ReadableBuffer, new: ReadableBuffer, count: SupportsIndex = -1, /) -> bytes: ...
707 def removeprefix(self, prefix: ReadableBuffer, /) -> bytes: ...
708 def removesuffix(self, suffix: ReadableBuffer, /) -> bytes: ...
709 def rfind(
710 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
711 ) -> int: ...
712 def rindex(
713 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
714 ) -> int: ...
715 def rjust(self, width: SupportsIndex, fillchar: bytes | bytearray = b" ", /) -> bytes: ...
716 def rpartition(self, sep: ReadableBuffer, /) -> tuple[bytes, bytes, bytes]: ...
717 def rsplit(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytes]: ...
718 def rstrip(self, bytes: ReadableBuffer | None = None, /) -> bytes: ...
719 def split(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytes]: ...
720 def splitlines(self, keepends: bool = False) -> list[bytes]: ...
721 def startswith(
722 self,
723 prefix: ReadableBuffer | tuple[ReadableBuffer, ...],
724 start: SupportsIndex | None = None,
725 end: SupportsIndex | None = None,
726 /,
727 ) -> bool: ...
728 def strip(self, bytes: ReadableBuffer | None = None, /) -> bytes: ...
729 def swapcase(self) -> bytes: ...
730 def title(self) -> bytes: ...
731 def translate(self, table: ReadableBuffer | None, /, delete: ReadableBuffer = b"") -> bytes: ...
732 def upper(self) -> bytes: ...
733 def zfill(self, width: SupportsIndex, /) -> bytes: ...
734 if sys.version_info >= (3, 14):
735 @classmethod
736 def fromhex(cls, string: str | ReadableBuffer, /) -> Self: ...
737 else:
738 @classmethod
739 def fromhex(cls, string: str, /) -> Self: ...
740
741 @staticmethod
742 def maketrans(frm: ReadableBuffer, to: ReadableBuffer, /) -> bytes: ...
743 def __len__(self) -> int: ...
744 def __iter__(self) -> Iterator[int]: ...
745 def __hash__(self) -> int: ...
746 @overload
747 def __getitem__(self, key: SupportsIndex, /) -> int: ...
748 @overload
749 def __getitem__(self, key: slice[SupportsIndex | None], /) -> bytes: ...
750 def __add__(self, value: ReadableBuffer, /) -> bytes: ...
751 def __mul__(self, value: SupportsIndex, /) -> bytes: ...
752 def __rmul__(self, value: SupportsIndex, /) -> bytes: ...
753 def __mod__(self, value: Any, /) -> bytes: ...
754 # Incompatible with Sequence.__contains__
755 def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
756 def __eq__(self, value: object, /) -> bool: ...
757 def __ne__(self, value: object, /) -> bool: ...
758 def __lt__(self, value: bytes, /) -> bool: ...
759 def __le__(self, value: bytes, /) -> bool: ...
760 def __gt__(self, value: bytes, /) -> bool: ...
761 def __ge__(self, value: bytes, /) -> bool: ...
762 def __getnewargs__(self) -> tuple[bytes]: ...
763 if sys.version_info >= (3, 11):
764 def __bytes__(self) -> bytes: ...
765
766 def __buffer__(self, flags: int, /) -> memoryview: ...
767
768 @disjoint_base
769 class bytearray(MutableSequence[int]):
770 @overload
771 def __init__(self) -> None: ...
772 @overload
773 def __init__(self, ints: Iterable[SupportsIndex] | SupportsIndex | ReadableBuffer, /) -> None: ...
774 @overload
775 def __init__(self, string: str, /, encoding: str, errors: str = "strict") -> None: ...
776 def append(self, item: SupportsIndex, /) -> None: ...
777 def capitalize(self) -> bytearray: ...
778 def center(self, width: SupportsIndex, fillchar: bytes = b" ", /) -> bytearray: ...
779 def count(
780 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
781 ) -> int: ...
782 def copy(self) -> bytearray: ...
783 def decode(self, encoding: str = "utf-8", errors: str = "strict") -> str: ...
784 def endswith(
785 self,
786 suffix: ReadableBuffer | tuple[ReadableBuffer, ...],
787 start: SupportsIndex | None = None,
788 end: SupportsIndex | None = None,
789 /,
790 ) -> bool: ...
791 def expandtabs(self, tabsize: SupportsIndex = 8) -> bytearray: ...
792 def extend(self, iterable_of_ints: Iterable[SupportsIndex], /) -> None: ...
793 def find(
794 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
795 ) -> int: ...
796 def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = 1) -> str: ...
797 def index(
798 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
799 ) -> int: ...
800 def insert(self, index: SupportsIndex, item: SupportsIndex, /) -> None: ...
801 def isalnum(self) -> bool: ...
802 def isalpha(self) -> bool: ...
803 def isascii(self) -> bool: ...
804 def isdigit(self) -> bool: ...
805 def islower(self) -> bool: ...
806 def isspace(self) -> bool: ...
807 def istitle(self) -> bool: ...
808 def isupper(self) -> bool: ...
809 def join(self, iterable_of_bytes: Iterable[ReadableBuffer], /) -> bytearray: ...
810 def ljust(self, width: SupportsIndex, fillchar: bytes | bytearray = b" ", /) -> bytearray: ...
811 def lower(self) -> bytearray: ...
812 def lstrip(self, bytes: ReadableBuffer | None = None, /) -> bytearray: ...
813 def partition(self, sep: ReadableBuffer, /) -> tuple[bytearray, bytearray, bytearray]: ...
814 def pop(self, index: int = -1, /) -> int: ...
815 def remove(self, value: int, /) -> None: ...
816 def removeprefix(self, prefix: ReadableBuffer, /) -> bytearray: ...
817 def removesuffix(self, suffix: ReadableBuffer, /) -> bytearray: ...
818 def replace(self, old: ReadableBuffer, new: ReadableBuffer, count: SupportsIndex = -1, /) -> bytearray: ...
819 def rfind(
820 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
821 ) -> int: ...
822 def rindex(
823 self, sub: ReadableBuffer | SupportsIndex, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
824 ) -> int: ...
825 def rjust(self, width: SupportsIndex, fillchar: bytes | bytearray = b" ", /) -> bytearray: ...
826 def rpartition(self, sep: ReadableBuffer, /) -> tuple[bytearray, bytearray, bytearray]: ...
827 def rsplit(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytearray]: ...
828 def rstrip(self, bytes: ReadableBuffer | None = None, /) -> bytearray: ...
829 def split(self, sep: ReadableBuffer | None = None, maxsplit: SupportsIndex = -1) -> list[bytearray]: ...
830 def splitlines(self, keepends: bool = False) -> list[bytearray]: ...
831 def startswith(
832 self,
833 prefix: ReadableBuffer | tuple[ReadableBuffer, ...],
834 start: SupportsIndex | None = None,
835 end: SupportsIndex | None = None,
836 /,
837 ) -> bool: ...
838 def strip(self, bytes: ReadableBuffer | None = None, /) -> bytearray: ...
839 def swapcase(self) -> bytearray: ...
840 def title(self) -> bytearray: ...
841 def translate(self, table: ReadableBuffer | None, /, delete: bytes = b"") -> bytearray: ...
842 def upper(self) -> bytearray: ...
843 def zfill(self, width: SupportsIndex, /) -> bytearray: ...
844 if sys.version_info >= (3, 14):
845 @classmethod
846 def fromhex(cls, string: str | ReadableBuffer, /) -> Self: ...
847 else:
848 @classmethod
849 def fromhex(cls, string: str, /) -> Self: ...
850
851 @staticmethod
852 def maketrans(frm: ReadableBuffer, to: ReadableBuffer, /) -> bytes: ...
853 def __len__(self) -> int: ...
854 def __iter__(self) -> Iterator[int]: ...
855 __hash__: ClassVar[None] # type: ignore[assignment]
856 @overload
857 def __getitem__(self, key: SupportsIndex, /) -> int: ...
858 @overload
859 def __getitem__(self, key: slice[SupportsIndex | None], /) -> bytearray: ...
860 @overload
861 def __setitem__(self, key: SupportsIndex, value: SupportsIndex, /) -> None: ...
862 @overload
863 def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[SupportsIndex] | bytes, /) -> None: ...
864 def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> None: ...
865 def __add__(self, value: ReadableBuffer, /) -> bytearray: ...
866 # The superclass wants us to accept Iterable[int], but that fails at runtime.
867 def __iadd__(self, value: ReadableBuffer, /) -> Self: ... # type: ignore[override]
868 def __mul__(self, value: SupportsIndex, /) -> bytearray: ...
869 def __rmul__(self, value: SupportsIndex, /) -> bytearray: ...
870 def __imul__(self, value: SupportsIndex, /) -> Self: ...
871 def __mod__(self, value: Any, /) -> bytes: ...
872 # Incompatible with Sequence.__contains__
873 def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
874 def __eq__(self, value: object, /) -> bool: ...
875 def __ne__(self, value: object, /) -> bool: ...
876 def __lt__(self, value: ReadableBuffer, /) -> bool: ...
877 def __le__(self, value: ReadableBuffer, /) -> bool: ...
878 def __gt__(self, value: ReadableBuffer, /) -> bool: ...
879 def __ge__(self, value: ReadableBuffer, /) -> bool: ...
880 def __alloc__(self) -> int: ...
881 def __buffer__(self, flags: int, /) -> memoryview: ...
882 def __release_buffer__(self, buffer: memoryview, /) -> None: ...
883 if sys.version_info >= (3, 14):
884 def resize(self, size: int, /) -> None: ...
885
886 _IntegerFormats: TypeAlias = Literal[
887 "b", "B", "@b", "@B", "h", "H", "@h", "@H", "i", "I", "@i", "@I", "l", "L", "@l", "@L", "q", "Q", "@q", "@Q", "P", "@P"
888 ]
889
890 @final
891 class memoryview(Sequence[_I]):
892 @property
893 def format(self) -> str: ...
894 @property
895 def itemsize(self) -> int: ...
896 @property
897 def shape(self) -> tuple[int, ...] | None: ...
898 @property
899 def strides(self) -> tuple[int, ...] | None: ...
900 @property
901 def suboffsets(self) -> tuple[int, ...] | None: ...
902 @property
903 def readonly(self) -> bool: ...
904 @property
905 def ndim(self) -> int: ...
906 @property
907 def obj(self) -> ReadableBuffer: ...
908 @property
909 def c_contiguous(self) -> bool: ...
910 @property
911 def f_contiguous(self) -> bool: ...
912 @property
913 def contiguous(self) -> bool: ...
914 @property
915 def nbytes(self) -> int: ...
916 def __new__(cls, obj: ReadableBuffer) -> Self: ...
917 def __enter__(self) -> Self: ...
918 def __exit__(
919 self,
920 exc_type: type[BaseException] | None, # noqa: PYI036 # This is the module declaring BaseException
921 exc_val: BaseException | None,
922 exc_tb: TracebackType | None,
923 /,
924 ) -> None: ...
925 @overload
926 def cast(self, format: Literal["c", "@c"], shape: list[int] | tuple[int, ...] = ...) -> memoryview[bytes]: ...
927 @overload
928 def cast(self, format: Literal["f", "@f", "d", "@d"], shape: list[int] | tuple[int, ...] = ...) -> memoryview[float]: ...
929 @overload
930 def cast(self, format: Literal["?"], shape: list[int] | tuple[int, ...] = ...) -> memoryview[bool]: ...
931 @overload
932 def cast(self, format: _IntegerFormats, shape: list[int] | tuple[int, ...] = ...) -> memoryview: ...
933 @overload
934 def __getitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], /) -> _I: ...
935 @overload
936 def __getitem__(self, key: slice[SupportsIndex | None], /) -> memoryview[_I]: ...
937 def __contains__(self, x: object, /) -> bool: ...
938 def __iter__(self) -> Iterator[_I]: ...
939 def __len__(self) -> int: ...
940 def __eq__(self, value: object, /) -> bool: ...
941 def __hash__(self) -> int: ...
942 @overload
943 def __setitem__(self, key: slice[SupportsIndex | None], value: ReadableBuffer, /) -> None: ...
944 @overload
945 def __setitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], value: _I, /) -> None: ...
946 if sys.version_info >= (3, 10):
947 def tobytes(self, order: Literal["C", "F", "A"] | None = "C") -> bytes: ...
948 else:
949 def tobytes(self, order: Literal["C", "F", "A"] | None = None) -> bytes: ...
950
951 def tolist(self) -> list[int]: ...
952 def toreadonly(self) -> memoryview: ...
953 def release(self) -> None: ...
954 def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = 1) -> str: ...
955 def __buffer__(self, flags: int, /) -> memoryview: ...
956 def __release_buffer__(self, buffer: memoryview, /) -> None: ...
957 if sys.version_info >= (3, 14):
958 def index(self, value: object, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
959 def count(self, value: object, /) -> int: ...
960 else:
961 # These are inherited from the Sequence ABC, but don't actually exist on memoryview.
962 # See https://github.com/python/cpython/issues/125420
963 index: ClassVar[None] # type: ignore[assignment]
964 count: ClassVar[None] # type: ignore[assignment]
965
966 if sys.version_info >= (3, 14):
967 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
968
969 @final
970 class bool(int):
971 def __new__(cls, o: object = False, /) -> Self: ...
972 # The following overloads could be represented more elegantly with a TypeVar("_B", bool, int),
973 # however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880).
974 @overload
975 def __and__(self, value: bool, /) -> bool: ...
976 @overload
977 def __and__(self, value: int, /) -> int: ...
978 @overload
979 def __or__(self, value: bool, /) -> bool: ...
980 @overload
981 def __or__(self, value: int, /) -> int: ...
982 @overload
983 def __xor__(self, value: bool, /) -> bool: ...
984 @overload
985 def __xor__(self, value: int, /) -> int: ...
986 @overload
987 def __rand__(self, value: bool, /) -> bool: ...
988 @overload
989 def __rand__(self, value: int, /) -> int: ...
990 @overload
991 def __ror__(self, value: bool, /) -> bool: ...
992 @overload
993 def __ror__(self, value: int, /) -> int: ...
994 @overload
995 def __rxor__(self, value: bool, /) -> bool: ...
996 @overload
997 def __rxor__(self, value: int, /) -> int: ...
998 def __getnewargs__(self) -> tuple[int]: ...
999 @deprecated("Will throw an error in Python 3.16. Use `not` for logical negation of bools instead.")
1000 def __invert__(self) -> int: ...
1001
1002 @final
1003 class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):
1004 @property
1005 def start(self) -> _StartT_co: ...
1006 @property
1007 def step(self) -> _StepT_co: ...
1008 @property
1009 def stop(self) -> _StopT_co: ...
1010 # Note: __new__ overloads map `None` to `Any`, since users expect slice(x, None)
1011 # to be compatible with slice(None, x).
1012 # generic slice --------------------------------------------------------------------
1013 @overload
1014 def __new__(cls, start: None, stop: None = None, step: None = None, /) -> slice[Any, Any, Any]: ...
1015 # unary overloads ------------------------------------------------------------------
1016 @overload
1017 def __new__(cls, stop: _T2, /) -> slice[Any, _T2, Any]: ...
1018 # binary overloads -----------------------------------------------------------------
1019 @overload
1020 def __new__(cls, start: _T1, stop: None, step: None = None, /) -> slice[_T1, Any, Any]: ...
1021 @overload
1022 def __new__(cls, start: None, stop: _T2, step: None = None, /) -> slice[Any, _T2, Any]: ...
1023 @overload
1024 def __new__(cls, start: _T1, stop: _T2, step: None = None, /) -> slice[_T1, _T2, Any]: ...
1025 # ternary overloads ----------------------------------------------------------------
1026 @overload
1027 def __new__(cls, start: None, stop: None, step: _T3, /) -> slice[Any, Any, _T3]: ...
1028 @overload
1029 def __new__(cls, start: _T1, stop: None, step: _T3, /) -> slice[_T1, Any, _T3]: ...
1030 @overload
1031 def __new__(cls, start: None, stop: _T2, step: _T3, /) -> slice[Any, _T2, _T3]: ...
1032 @overload
1033 def __new__(cls, start: _T1, stop: _T2, step: _T3, /) -> slice[_T1, _T2, _T3]: ...
1034 def __eq__(self, value: object, /) -> bool: ...
1035 if sys.version_info >= (3, 12):
1036 def __hash__(self) -> int: ...
1037 else:
1038 __hash__: ClassVar[None] # type: ignore[assignment]
1039
1040 def indices(self, len: SupportsIndex, /) -> tuple[int, int, int]: ...
1041
1042 @disjoint_base
1043 class tuple(Sequence[_T_co]):
1044 def __new__(cls, iterable: Iterable[_T_co] = (), /) -> Self: ...
1045 def __len__(self) -> int: ...
1046 def __contains__(self, key: object, /) -> bool: ...
1047 @overload
1048 def __getitem__(self, key: int, /) -> _T_co: ...
1049 @overload
1050 def __getitem__(self, key: slice[int | None], /) -> tuple[_T_co, ...]: ...
1051 def __iter__(self) -> Iterator[_T_co]: ...
1052 def __lt__(self, value: tuple[_T_co, ...], /) -> bool: ...
1053 def __le__(self, value: tuple[_T_co, ...], /) -> bool: ...
1054 def __gt__(self, value: tuple[_T_co, ...], /) -> bool: ...
1055 def __ge__(self, value: tuple[_T_co, ...], /) -> bool: ...
1056 def __eq__(self, value: object, /) -> bool: ...
1057 def __hash__(self) -> int: ...
1058 @overload
1059 def __add__(self, value: tuple[_T_co, ...], /) -> tuple[_T_co, ...]: ...
1060 @overload
1061 def __add__(self, value: tuple[_T, ...], /) -> tuple[_T_co | _T, ...]: ...
1062 def __mul__(self, value: SupportsIndex, /) -> tuple[_T_co, ...]: ...
1063 def __rmul__(self, value: SupportsIndex, /) -> tuple[_T_co, ...]: ...
1064 def count(self, value: Any, /) -> int: ...
1065 def index(self, value: Any, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
1066 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
1067
1068 @disjoint_base
1069 class list(MutableSequence[_T]):
1070 @overload
1071 def __init__(self) -> None: ...
1072 @overload
1073 def __init__(self, iterable: Iterable[_T], /) -> None: ...
1074 def copy(self) -> list[_T]: ...
1075 def append(self, object: _T, /) -> None: ...
1076 def extend(self, iterable: Iterable[_T], /) -> None: ...
1077 def pop(self, index: SupportsIndex = -1, /) -> _T: ...
1078 # Signature of `list.index` should be kept in line with `collections.UserList.index()`
1079 # and multiprocessing.managers.ListProxy.index()
1080 def index(self, value: _T, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
1081 def count(self, value: _T, /) -> int: ...
1082 def insert(self, index: SupportsIndex, object: _T, /) -> None: ...
1083 def remove(self, value: _T, /) -> None: ...
1084 # Signature of `list.sort` should be kept inline with `collections.UserList.sort()`
1085 # and multiprocessing.managers.ListProxy.sort()
1086 #
1087 # Use list[SupportsRichComparisonT] for the first overload rather than [SupportsRichComparison]
1088 # to work around invariance
1089 @overload
1090 def sort(self: list[SupportsRichComparisonT], *, key: None = None, reverse: bool = False) -> None: ...
1091 @overload
1092 def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = False) -> None: ...
1093 def __len__(self) -> int: ...
1094 def __iter__(self) -> Iterator[_T]: ...
1095 __hash__: ClassVar[None] # type: ignore[assignment]
1096 @overload
1097 def __getitem__(self, i: int, /) -> _T: ...
1098 @overload
1099 def __getitem__(self, s: slice[int | None], /) -> list[_T]: ...
1100 @overload
1101 def __setitem__(self, key: SupportsIndex, value: _T, /) -> None: ...
1102 @overload
1103 def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[_T], /) -> None: ...
1104 def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> None: ...
1105 # Overloading looks unnecessary, but is needed to work around complex mypy problems
1106 @overload
1107 def __add__(self, value: list[_T], /) -> list[_T]: ...
1108 @overload
1109 def __add__(self, value: list[_S], /) -> list[_S | _T]: ...
1110 def __iadd__(self, value: Iterable[_T], /) -> Self: ... # type: ignore[misc]
1111 def __mul__(self, value: SupportsIndex, /) -> list[_T]: ...
1112 def __rmul__(self, value: SupportsIndex, /) -> list[_T]: ...
1113 def __imul__(self, value: SupportsIndex, /) -> Self: ...
1114 def __contains__(self, key: object, /) -> bool: ...
1115 def __reversed__(self) -> Iterator[_T]: ...
1116 def __gt__(self, value: list[_T], /) -> bool: ...
1117 def __ge__(self, value: list[_T], /) -> bool: ...
1118 def __lt__(self, value: list[_T], /) -> bool: ...
1119 def __le__(self, value: list[_T], /) -> bool: ...
1120 def __eq__(self, value: object, /) -> bool: ...
1121 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
1122
1123 @disjoint_base
1124 class dict(MutableMapping[_KT, _VT]):
1125 # __init__ should be kept roughly in line with `collections.UserDict.__init__`, which has similar semantics
1126 # Also multiprocessing.managers.SyncManager.dict()
1127 @overload
1128 def __init__(self, /) -> None: ...
1129 @overload
1130 def __init__(self, /, **kwargs: _VT) -> None: ...
1131 @overload
1132 def __init__(self, map: Mapping[_KT, _VT], /) -> None: ...
1133 @overload
1134 def __init__(
1135 self,
1136 map: Mapping[str, _VT],
1137 /,
1138 **kwargs: _VT,
1139 ) -> None: ...
1140 @overload
1141 def __init__(self, iterable: Iterable[tuple[_KT, _VT]], /) -> None: ...
1142 @overload
1143 def __init__(
1144 self: dict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780
1145 iterable: Iterable[tuple[str, _VT]],
1146 /,
1147 **kwargs: _VT,
1148 ) -> None: ...
1149 # Next two overloads are for dict(string.split(sep) for string in iterable)
1150 # Cannot be Iterable[Sequence[_T]] or otherwise dict(["foo", "bar", "baz"]) is not an error
1151 @overload
1152 def __init__(self: dict[str, str], iterable: Iterable[list[str]], /) -> None: ...
1153 @overload
1154 def __init__(self: dict[bytes, bytes], iterable: Iterable[list[bytes]], /) -> None: ...
1155 def __new__(cls, /, *args: Any, **kwargs: Any) -> Self: ...
1156 def copy(self) -> dict[_KT, _VT]: ...
1157 def keys(self) -> dict_keys[_KT, _VT]: ...
1158 def values(self) -> dict_values[_KT, _VT]: ...
1159 def items(self) -> dict_items[_KT, _VT]: ...
1160 # Signature of `dict.fromkeys` should be kept identical to
1161 # `fromkeys` methods of `OrderedDict`/`ChainMap`/`UserDict` in `collections`
1162 # TODO: the true signature of `dict.fromkeys` is not expressible in the current type system.
1163 # See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
1164 @classmethod
1165 @overload
1166 def fromkeys(cls, iterable: Iterable[_T], value: None = None, /) -> dict[_T, Any | None]: ...
1167 @classmethod
1168 @overload
1169 def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> dict[_T, _S]: ...
1170 # Positional-only in dict, but not in MutableMapping
1171 @overload # type: ignore[override]
1172 def get(self, key: _KT, default: None = None, /) -> _VT | None: ...
1173 @overload
1174 def get(self, key: _KT, default: _VT, /) -> _VT: ...
1175 @overload
1176 def get(self, key: _KT, default: _T, /) -> _VT | _T: ...
1177 @overload
1178 def pop(self, key: _KT, /) -> _VT: ...
1179 @overload
1180 def pop(self, key: _KT, default: _VT, /) -> _VT: ...
1181 @overload
1182 def pop(self, key: _KT, default: _T, /) -> _VT | _T: ...
1183 def __len__(self) -> int: ...
1184 def __getitem__(self, key: _KT, /) -> _VT: ...
1185 def __setitem__(self, key: _KT, value: _VT, /) -> None: ...
1186 def __delitem__(self, key: _KT, /) -> None: ...
1187 def __iter__(self) -> Iterator[_KT]: ...
1188 def __eq__(self, value: object, /) -> bool: ...
1189 def __reversed__(self) -> Iterator[_KT]: ...
1190 __hash__: ClassVar[None] # type: ignore[assignment]
1191 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
1192 def __or__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
1193 def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
1194 # dict.__ior__ should be kept roughly in line with MutableMapping.update()
1195 @overload # type: ignore[misc]
1196 def __ior__(self, value: SupportsKeysAndGetItem[_KT, _VT], /) -> Self: ...
1197 @overload
1198 def __ior__(self, value: Iterable[tuple[_KT, _VT]], /) -> Self: ...
1199
1200 @disjoint_base
1201 class set(MutableSet[_T]):
1202 @overload
1203 def __init__(self) -> None: ...
1204 @overload
1205 def __init__(self, iterable: Iterable[_T], /) -> None: ...
1206 def add(self, element: _T, /) -> None: ...
1207 def copy(self) -> set[_T]: ...
1208 def difference(self, *s: Iterable[object]) -> set[_T]: ...
1209 def difference_update(self, *s: Iterable[object]) -> None: ...
1210 def discard(self, element: object, /) -> None: ...
1211 def intersection(self, *s: Iterable[object]) -> set[_T]: ...
1212 def intersection_update(self, *s: Iterable[object]) -> None: ...
1213 def isdisjoint(self, s: Iterable[object], /) -> bool: ...
1214 def issubset(self, s: Iterable[object], /) -> bool: ...
1215 def issuperset(self, s: Iterable[object], /) -> bool: ...
1216 def remove(self, element: _T, /) -> None: ...
1217 def symmetric_difference(self, s: Iterable[_S], /) -> set[_T | _S]: ...
1218 def symmetric_difference_update(self, s: Iterable[_T], /) -> None: ...
1219 def union(self, *s: Iterable[_S]) -> set[_T | _S]: ...
1220 def update(self, *s: Iterable[_T]) -> None: ...
1221 def __len__(self) -> int: ...
1222 def __contains__(self, o: object, /) -> bool: ...
1223 def __iter__(self) -> Iterator[_T]: ...
1224 def __and__(self, value: AbstractSet[object], /) -> set[_T]: ...
1225 def __iand__(self, value: AbstractSet[object], /) -> Self: ...
1226 def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
1227 def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
1228 def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ...
1229 def __isub__(self, value: AbstractSet[object], /) -> Self: ...
1230 def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
1231 def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
1232 def __le__(self, value: AbstractSet[object], /) -> bool: ...
1233 def __lt__(self, value: AbstractSet[object], /) -> bool: ...
1234 def __ge__(self, value: AbstractSet[object], /) -> bool: ...
1235 def __gt__(self, value: AbstractSet[object], /) -> bool: ...
1236 def __eq__(self, value: object, /) -> bool: ...
1237 __hash__: ClassVar[None] # type: ignore[assignment]
1238 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
1239
1240 @disjoint_base
1241 class frozenset(AbstractSet[_T_co]):
1242 @overload
1243 def __new__(cls) -> Self: ...
1244 @overload
1245 def __new__(cls, iterable: Iterable[_T_co], /) -> Self: ...
1246 def copy(self) -> frozenset[_T_co]: ...
1247 def difference(self, *s: Iterable[object]) -> frozenset[_T_co]: ...
1248 def intersection(self, *s: Iterable[object]) -> frozenset[_T_co]: ...
1249 def isdisjoint(self, s: Iterable[object], /) -> bool: ...
1250 def issubset(self, s: Iterable[object], /) -> bool: ...
1251 def issuperset(self, s: Iterable[object], /) -> bool: ...
1252 def symmetric_difference(self, s: Iterable[_S], /) -> frozenset[_T_co | _S]: ...
1253 def union(self, *s: Iterable[_S]) -> frozenset[_T_co | _S]: ...
1254 def __len__(self) -> int: ...
1255 def __contains__(self, o: object, /) -> bool: ...
1256 def __iter__(self) -> Iterator[_T_co]: ...
1257 def __and__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
1258 def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
1259 def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
1260 def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
1261 def __le__(self, value: AbstractSet[object], /) -> bool: ...
1262 def __lt__(self, value: AbstractSet[object], /) -> bool: ...
1263 def __ge__(self, value: AbstractSet[object], /) -> bool: ...
1264 def __gt__(self, value: AbstractSet[object], /) -> bool: ...
1265 def __eq__(self, value: object, /) -> bool: ...
1266 def __hash__(self) -> int: ...
1267 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
1268
1269 @disjoint_base
1270 class enumerate(Generic[_T]):
1271 def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
1272 def __iter__(self) -> Self: ...
1273 def __next__(self) -> tuple[int, _T]: ...
1274 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
1275
1276 @final
1277 class range(Sequence[int]):
1278 @property
1279 def start(self) -> int: ...
1280 @property
1281 def stop(self) -> int: ...
1282 @property
1283 def step(self) -> int: ...
1284 @overload
1285 def __new__(cls, stop: SupportsIndex, /) -> Self: ...
1286 @overload
1287 def __new__(cls, start: SupportsIndex, stop: SupportsIndex, step: SupportsIndex = 1, /) -> Self: ...
1288 def count(self, value: int, /) -> int: ...
1289 def index(self, value: int, /) -> int: ... # type: ignore[override]
1290 def __len__(self) -> int: ...
1291 def __eq__(self, value: object, /) -> bool: ...
1292 def __hash__(self) -> int: ...
1293 def __contains__(self, key: object, /) -> bool: ...
1294 def __iter__(self) -> Iterator[int]: ...
1295 @overload
1296 def __getitem__(self, key: SupportsIndex, /) -> int: ...
1297 @overload
1298 def __getitem__(self, key: slice[SupportsIndex | None], /) -> range: ...
1299 def __reversed__(self) -> Iterator[int]: ...
1300
1301 @disjoint_base
1302 class property:
1303 fget: Callable[[Any], Any] | None
1304 fset: Callable[[Any, Any], None] | None
1305 fdel: Callable[[Any], None] | None
1306 __isabstractmethod__: bool
1307 if sys.version_info >= (3, 13):
1308 __name__: str
1309
1310 def __init__(
1311 self,
1312 fget: Callable[[Any], Any] | None = None,
1313 fset: Callable[[Any, Any], None] | None = None,
1314 fdel: Callable[[Any], None] | None = None,
1315 doc: str | None = None,
1316 ) -> None: ...
1317 def getter(self, fget: Callable[[Any], Any], /) -> property: ...
1318 def setter(self, fset: Callable[[Any, Any], None], /) -> property: ...
1319 def deleter(self, fdel: Callable[[Any], None], /) -> property: ...
1320 @overload
1321 def __get__(self, instance: None, owner: type, /) -> Self: ...
1322 @overload
1323 def __get__(self, instance: Any, owner: type | None = None, /) -> Any: ...
1324 def __set__(self, instance: Any, value: Any, /) -> None: ...
1325 def __delete__(self, instance: Any, /) -> None: ...
1326
1327 def abs(x: SupportsAbs[_T], /) -> _T: ...
1328 def all(iterable: Iterable[object], /) -> bool: ...
1329 def any(iterable: Iterable[object], /) -> bool: ...
1330 def ascii(obj: object, /) -> str: ...
1331 def bin(number: SupportsIndex, /) -> str: ...
1332 def breakpoint(*args: Any, **kws: Any) -> None: ...
1333 def callable(obj: object, /) -> TypeIs[Callable[..., object]]: ...
1334 def chr(i: SupportsIndex, /) -> str: ...
1335
1336 if sys.version_info >= (3, 10):
1337 def aiter(async_iterable: SupportsAiter[_SupportsAnextT_co], /) -> _SupportsAnextT_co: ...
1338 @type_check_only
1339 class _SupportsSynchronousAnext(Protocol[_AwaitableT_co]):
1340 def __anext__(self) -> _AwaitableT_co: ...
1341
1342 @overload
1343 # `anext` is not, in fact, an async function. When default is not provided
1344 # `anext` is just a passthrough for `obj.__anext__`
1345 # See discussion in #7491 and pure-Python implementation of `anext` at https://github.com/python/cpython/blob/ea786a882b9ed4261eafabad6011bc7ef3b5bf94/Lib/test/test_asyncgen.py#L52-L80
1346 def anext(i: _SupportsSynchronousAnext[_AwaitableT], /) -> _AwaitableT: ...
1347 @overload
1348 async def anext(i: SupportsAnext[_T], default: _VT, /) -> _T | _VT: ...
1349
1350 # compile() returns a CodeType, unless the flags argument includes PyCF_ONLY_AST (=1024),
1351 # in which case it returns ast.AST. We have overloads for flag 0 (the default) and for
1352 # explicitly passing PyCF_ONLY_AST. We fall back to Any for other values of flags.
1353 @overload
1354 def compile(
1355 source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1356 filename: str | bytes | PathLike[Any],
1357 mode: str,
1358 flags: Literal[0],
1359 dont_inherit: bool = False,
1360 optimize: int = -1,
1361 *,
1362 _feature_version: int = -1,
1363 ) -> CodeType: ...
1364 @overload
1365 def compile(
1366 source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1367 filename: str | bytes | PathLike[Any],
1368 mode: str,
1369 *,
1370 dont_inherit: bool = False,
1371 optimize: int = -1,
1372 _feature_version: int = -1,
1373 ) -> CodeType: ...
1374 @overload
1375 def compile(
1376 source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1377 filename: str | bytes | PathLike[Any],
1378 mode: str,
1379 flags: Literal[1024],
1380 dont_inherit: bool = False,
1381 optimize: int = -1,
1382 *,
1383 _feature_version: int = -1,
1384 ) -> _ast.AST: ...
1385 @overload
1386 def compile(
1387 source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1388 filename: str | bytes | PathLike[Any],
1389 mode: str,
1390 flags: int,
1391 dont_inherit: bool = False,
1392 optimize: int = -1,
1393 *,
1394 _feature_version: int = -1,
1395 ) -> Any: ...
1396
1397 copyright: _sitebuiltins._Printer
1398 credits: _sitebuiltins._Printer
1399
1400 def delattr(obj: object, name: str, /) -> None: ...
1401 def dir(o: object = ..., /) -> list[str]: ...
1402 @overload
1403 def divmod(x: SupportsDivMod[_T_contra, _T_co], y: _T_contra, /) -> _T_co: ...
1404 @overload
1405 def divmod(x: _T_contra, y: SupportsRDivMod[_T_contra, _T_co], /) -> _T_co: ...
1406
1407 # The `globals` argument to `eval` has to be `dict[str, Any]` rather than `dict[str, object]` due to invariance.
1408 # (The `globals` argument has to be a "real dict", rather than any old mapping, unlike the `locals` argument.)
1409 if sys.version_info >= (3, 13):
1410 def eval(
1411 source: str | ReadableBuffer | CodeType,
1412 /,
1413 globals: dict[str, Any] | None = None,
1414 locals: Mapping[str, object] | None = None,
1415 ) -> Any: ...
1416
1417 else:
1418 def eval(
1419 source: str | ReadableBuffer | CodeType,
1420 globals: dict[str, Any] | None = None,
1421 locals: Mapping[str, object] | None = None,
1422 /,
1423 ) -> Any: ...
1424
1425 # Comment above regarding `eval` applies to `exec` as well
1426 if sys.version_info >= (3, 13):
1427 def exec(
1428 source: str | ReadableBuffer | CodeType,
1429 /,
1430 globals: dict[str, Any] | None = None,
1431 locals: Mapping[str, object] | None = None,
1432 *,
1433 closure: tuple[CellType, ...] | None = None,
1434 ) -> None: ...
1435
1436 elif sys.version_info >= (3, 11):
1437 def exec(
1438 source: str | ReadableBuffer | CodeType,
1439 globals: dict[str, Any] | None = None,
1440 locals: Mapping[str, object] | None = None,
1441 /,
1442 *,
1443 closure: tuple[CellType, ...] | None = None,
1444 ) -> None: ...
1445
1446 else:
1447 def exec(
1448 source: str | ReadableBuffer | CodeType,
1449 globals: dict[str, Any] | None = None,
1450 locals: Mapping[str, object] | None = None,
1451 /,
1452 ) -> None: ...
1453
1454 exit: _sitebuiltins.Quitter
1455
1456 @disjoint_base
1457 class filter(Generic[_T]):
1458 @overload
1459 def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
1460 @overload
1461 def __new__(cls, function: Callable[[_S], TypeGuard[_T]], iterable: Iterable[_S], /) -> Self: ...
1462 @overload
1463 def __new__(cls, function: Callable[[_S], TypeIs[_T]], iterable: Iterable[_S], /) -> Self: ...
1464 @overload
1465 def __new__(cls, function: Callable[[_T], Any], iterable: Iterable[_T], /) -> Self: ...
1466 def __iter__(self) -> Self: ...
1467 def __next__(self) -> _T: ...
1468
1469 def format(value: object, format_spec: str = "", /) -> str: ...
1470 @overload
1471 def getattr(o: object, name: str, /) -> Any: ...
1472
1473 # While technically covered by the last overload, spelling out the types for None, bool
1474 # and basic containers help mypy out in some tricky situations involving type context
1475 # (aka bidirectional inference)
1476 @overload
1477 def getattr(o: object, name: str, default: None, /) -> Any | None: ...
1478 @overload
1479 def getattr(o: object, name: str, default: bool, /) -> Any | bool: ...
1480 @overload
1481 def getattr(o: object, name: str, default: list[Any], /) -> Any | list[Any]: ...
1482 @overload
1483 def getattr(o: object, name: str, default: dict[Any, Any], /) -> Any | dict[Any, Any]: ...
1484 @overload
1485 def getattr(o: object, name: str, default: _T, /) -> Any | _T: ...
1486 def globals() -> dict[str, Any]: ...
1487 def hasattr(obj: object, name: str, /) -> bool: ...
1488 def hash(obj: object, /) -> int: ...
1489
1490 help: _sitebuiltins._Helper
1491
1492 def hex(number: SupportsIndex, /) -> str: ...
1493 def id(obj: object, /) -> int: ...
1494 def input(prompt: object = "", /) -> str: ...
1495 @type_check_only
1496 class _GetItemIterable(Protocol[_T_co]):
1497 def __getitem__(self, i: int, /) -> _T_co: ...
1498
1499 @overload
1500 def iter(object: SupportsIter[_SupportsNextT_co], /) -> _SupportsNextT_co: ...
1501 @overload
1502 def iter(object: _GetItemIterable[_T], /) -> Iterator[_T]: ...
1503 @overload
1504 def iter(object: Callable[[], _T | None], sentinel: None, /) -> Iterator[_T]: ...
1505 @overload
1506 def iter(object: Callable[[], _T], sentinel: object, /) -> Iterator[_T]: ...
1507
1508 if sys.version_info >= (3, 10):
1509 _ClassInfo: TypeAlias = type | types.UnionType | tuple[_ClassInfo, ...]
1510 else:
1511 _ClassInfo: TypeAlias = type | tuple[_ClassInfo, ...]
1512
1513 def isinstance(obj: object, class_or_tuple: _ClassInfo, /) -> bool: ...
1514 def issubclass(cls: type, class_or_tuple: _ClassInfo, /) -> bool: ...
1515 def len(obj: Sized, /) -> int: ...
1516
1517 license: _sitebuiltins._Printer
1518
1519 def locals() -> dict[str, Any]: ...
1520 @disjoint_base
1521 class map(Generic[_S]):
1522 # 3.14 adds `strict` argument.
1523 if sys.version_info >= (3, 14):
1524 @overload
1525 def __new__(cls, func: Callable[[_T1], _S], iterable: Iterable[_T1], /, *, strict: bool = False) -> Self: ...
1526 @overload
1527 def __new__(
1528 cls, func: Callable[[_T1, _T2], _S], iterable: Iterable[_T1], iter2: Iterable[_T2], /, *, strict: bool = False
1529 ) -> Self: ...
1530 @overload
1531 def __new__(
1532 cls,
1533 func: Callable[[_T1, _T2, _T3], _S],
1534 iterable: Iterable[_T1],
1535 iter2: Iterable[_T2],
1536 iter3: Iterable[_T3],
1537 /,
1538 *,
1539 strict: bool = False,
1540 ) -> Self: ...
1541 @overload
1542 def __new__(
1543 cls,
1544 func: Callable[[_T1, _T2, _T3, _T4], _S],
1545 iterable: Iterable[_T1],
1546 iter2: Iterable[_T2],
1547 iter3: Iterable[_T3],
1548 iter4: Iterable[_T4],
1549 /,
1550 *,
1551 strict: bool = False,
1552 ) -> Self: ...
1553 @overload
1554 def __new__(
1555 cls,
1556 func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
1557 iterable: Iterable[_T1],
1558 iter2: Iterable[_T2],
1559 iter3: Iterable[_T3],
1560 iter4: Iterable[_T4],
1561 iter5: Iterable[_T5],
1562 /,
1563 *,
1564 strict: bool = False,
1565 ) -> Self: ...
1566 @overload
1567 def __new__(
1568 cls,
1569 func: Callable[..., _S],
1570 iterable: Iterable[Any],
1571 iter2: Iterable[Any],
1572 iter3: Iterable[Any],
1573 iter4: Iterable[Any],
1574 iter5: Iterable[Any],
1575 iter6: Iterable[Any],
1576 /,
1577 *iterables: Iterable[Any],
1578 strict: bool = False,
1579 ) -> Self: ...
1580 else:
1581 @overload
1582 def __new__(cls, func: Callable[[_T1], _S], iterable: Iterable[_T1], /) -> Self: ...
1583 @overload
1584 def __new__(cls, func: Callable[[_T1, _T2], _S], iterable: Iterable[_T1], iter2: Iterable[_T2], /) -> Self: ...
1585 @overload
1586 def __new__(
1587 cls, func: Callable[[_T1, _T2, _T3], _S], iterable: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /
1588 ) -> Self: ...
1589 @overload
1590 def __new__(
1591 cls,
1592 func: Callable[[_T1, _T2, _T3, _T4], _S],
1593 iterable: Iterable[_T1],
1594 iter2: Iterable[_T2],
1595 iter3: Iterable[_T3],
1596 iter4: Iterable[_T4],
1597 /,
1598 ) -> Self: ...
1599 @overload
1600 def __new__(
1601 cls,
1602 func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
1603 iterable: Iterable[_T1],
1604 iter2: Iterable[_T2],
1605 iter3: Iterable[_T3],
1606 iter4: Iterable[_T4],
1607 iter5: Iterable[_T5],
1608 /,
1609 ) -> Self: ...
1610 @overload
1611 def __new__(
1612 cls,
1613 func: Callable[..., _S],
1614 iterable: Iterable[Any],
1615 iter2: Iterable[Any],
1616 iter3: Iterable[Any],
1617 iter4: Iterable[Any],
1618 iter5: Iterable[Any],
1619 iter6: Iterable[Any],
1620 /,
1621 *iterables: Iterable[Any],
1622 ) -> Self: ...
1623
1624 def __iter__(self) -> Self: ...
1625 def __next__(self) -> _S: ...
1626
1627 @overload
1628 def max(
1629 arg1: SupportsRichComparisonT, arg2: SupportsRichComparisonT, /, *_args: SupportsRichComparisonT, key: None = None
1630 ) -> SupportsRichComparisonT: ...
1631 @overload
1632 def max(arg1: _T, arg2: _T, /, *_args: _T, key: Callable[[_T], SupportsRichComparison]) -> _T: ...
1633 @overload
1634 def max(iterable: Iterable[SupportsRichComparisonT], /, *, key: None = None) -> SupportsRichComparisonT: ...
1635 @overload
1636 def max(iterable: Iterable[_T], /, *, key: Callable[[_T], SupportsRichComparison]) -> _T: ...
1637 @overload
1638 def max(iterable: Iterable[SupportsRichComparisonT], /, *, key: None = None, default: _T) -> SupportsRichComparisonT | _T: ...
1639 @overload
1640 def max(iterable: Iterable[_T1], /, *, key: Callable[[_T1], SupportsRichComparison], default: _T2) -> _T1 | _T2: ...
1641 @overload
1642 def min(
1643 arg1: SupportsRichComparisonT, arg2: SupportsRichComparisonT, /, *_args: SupportsRichComparisonT, key: None = None
1644 ) -> SupportsRichComparisonT: ...
1645 @overload
1646 def min(arg1: _T, arg2: _T, /, *_args: _T, key: Callable[[_T], SupportsRichComparison]) -> _T: ...
1647 @overload
1648 def min(iterable: Iterable[SupportsRichComparisonT], /, *, key: None = None) -> SupportsRichComparisonT: ...
1649 @overload
1650 def min(iterable: Iterable[_T], /, *, key: Callable[[_T], SupportsRichComparison]) -> _T: ...
1651 @overload
1652 def min(iterable: Iterable[SupportsRichComparisonT], /, *, key: None = None, default: _T) -> SupportsRichComparisonT | _T: ...
1653 @overload
1654 def min(iterable: Iterable[_T1], /, *, key: Callable[[_T1], SupportsRichComparison], default: _T2) -> _T1 | _T2: ...
1655 @overload
1656 def next(i: SupportsNext[_T], /) -> _T: ...
1657 @overload
1658 def next(i: SupportsNext[_T], default: _VT, /) -> _T | _VT: ...
1659 def oct(number: SupportsIndex, /) -> str: ...
1660
1661 _Opener: TypeAlias = Callable[[str, int], int]
1662
1663 # Text mode: always returns a TextIOWrapper
1664 @overload
1665 def open(
1666 file: FileDescriptorOrPath,
1667 mode: OpenTextMode = "r",
1668 buffering: int = -1,
1669 encoding: str | None = None,
1670 errors: str | None = None,
1671 newline: str | None = None,
1672 closefd: bool = True,
1673 opener: _Opener | None = None,
1674 ) -> TextIOWrapper: ...
1675
1676 # Unbuffered binary mode: returns a FileIO
1677 @overload
1678 def open(
1679 file: FileDescriptorOrPath,
1680 mode: OpenBinaryMode,
1681 buffering: Literal[0],
1682 encoding: None = None,
1683 errors: None = None,
1684 newline: None = None,
1685 closefd: bool = True,
1686 opener: _Opener | None = None,
1687 ) -> FileIO: ...
1688
1689 # Buffering is on: return BufferedRandom, BufferedReader, or BufferedWriter
1690 @overload
1691 def open(
1692 file: FileDescriptorOrPath,
1693 mode: OpenBinaryModeUpdating,
1694 buffering: Literal[-1, 1] = -1,
1695 encoding: None = None,
1696 errors: None = None,
1697 newline: None = None,
1698 closefd: bool = True,
1699 opener: _Opener | None = None,
1700 ) -> BufferedRandom: ...
1701 @overload
1702 def open(
1703 file: FileDescriptorOrPath,
1704 mode: OpenBinaryModeWriting,
1705 buffering: Literal[-1, 1] = -1,
1706 encoding: None = None,
1707 errors: None = None,
1708 newline: None = None,
1709 closefd: bool = True,
1710 opener: _Opener | None = None,
1711 ) -> BufferedWriter: ...
1712 @overload
1713 def open(
1714 file: FileDescriptorOrPath,
1715 mode: OpenBinaryModeReading,
1716 buffering: Literal[-1, 1] = -1,
1717 encoding: None = None,
1718 errors: None = None,
1719 newline: None = None,
1720 closefd: bool = True,
1721 opener: _Opener | None = None,
1722 ) -> BufferedReader: ...
1723
1724 # Buffering cannot be determined: fall back to BinaryIO
1725 @overload
1726 def open(
1727 file: FileDescriptorOrPath,
1728 mode: OpenBinaryMode,
1729 buffering: int = -1,
1730 encoding: None = None,
1731 errors: None = None,
1732 newline: None = None,
1733 closefd: bool = True,
1734 opener: _Opener | None = None,
1735 ) -> BinaryIO: ...
1736
1737 # Fallback if mode is not specified
1738 @overload
1739 def open(
1740 file: FileDescriptorOrPath,
1741 mode: str,
1742 buffering: int = -1,
1743 encoding: str | None = None,
1744 errors: str | None = None,
1745 newline: str | None = None,
1746 closefd: bool = True,
1747 opener: _Opener | None = None,
1748 ) -> IO[Any]: ...
1749 def ord(c: str | bytes | bytearray, /) -> int: ...
1750 @type_check_only
1751 class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol[_T_contra]): ...
1752
1753 @overload
1754 def print(
1755 *values: object,
1756 sep: str | None = " ",
1757 end: str | None = "\n",
1758 file: SupportsWrite[str] | None = None,
1759 flush: Literal[False] = False,
1760 ) -> None: ...
1761 @overload
1762 def print(
1763 *values: object, sep: str | None = " ", end: str | None = "\n", file: _SupportsWriteAndFlush[str] | None = None, flush: bool
1764 ) -> None: ...
1765
1766 _E_contra = TypeVar("_E_contra", contravariant=True)
1767 _M_contra = TypeVar("_M_contra", contravariant=True)
1768
1769 @type_check_only
1770 class _SupportsPow2(Protocol[_E_contra, _T_co]):
1771 def __pow__(self, other: _E_contra, /) -> _T_co: ...
1772
1773 @type_check_only
1774 class _SupportsPow3NoneOnly(Protocol[_E_contra, _T_co]):
1775 def __pow__(self, other: _E_contra, modulo: None = None, /) -> _T_co: ...
1776
1777 @type_check_only
1778 class _SupportsPow3(Protocol[_E_contra, _M_contra, _T_co]):
1779 def __pow__(self, other: _E_contra, modulo: _M_contra, /) -> _T_co: ...
1780
1781 _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed
1782 _SupportsPow2[Any, Any] | _SupportsPow3NoneOnly[Any, Any] | _SupportsPow3[Any, Any, Any]
1783 )
1784
1785 # TODO: `pow(int, int, Literal[0])` fails at runtime,
1786 # but adding a `NoReturn` overload isn't a good solution for expressing that (see #8566).
1787 @overload
1788 def pow(base: int, exp: int, mod: int) -> int: ...
1789 @overload
1790 def pow(base: int, exp: Literal[0], mod: None = None) -> Literal[1]: ...
1791 @overload
1792 def pow(base: int, exp: _PositiveInteger, mod: None = None) -> int: ...
1793 @overload
1794 def pow(base: int, exp: _NegativeInteger, mod: None = None) -> float: ...
1795
1796 # int base & positive-int exp -> int; int base & negative-int exp -> float
1797 # return type must be Any as `int | float` causes too many false-positive errors
1798 @overload
1799 def pow(base: int, exp: int, mod: None = None) -> Any: ...
1800 @overload
1801 def pow(base: _PositiveInteger, exp: float, mod: None = None) -> float: ...
1802 @overload
1803 def pow(base: _NegativeInteger, exp: float, mod: None = None) -> complex: ...
1804 @overload
1805 def pow(base: float, exp: int, mod: None = None) -> float: ...
1806
1807 # float base & float exp could return float or complex
1808 # return type must be Any (same as complex base, complex exp),
1809 # as `float | complex` causes too many false-positive errors
1810 @overload
1811 def pow(base: float, exp: complex | _SupportsSomeKindOfPow, mod: None = None) -> Any: ...
1812 @overload
1813 def pow(base: complex, exp: complex | _SupportsSomeKindOfPow, mod: None = None) -> complex: ...
1814 @overload
1815 def pow(base: _SupportsPow2[_E_contra, _T_co], exp: _E_contra, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap]
1816 @overload
1817 def pow(base: _SupportsPow3NoneOnly[_E_contra, _T_co], exp: _E_contra, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap]
1818 @overload
1819 def pow(base: _SupportsPow3[_E_contra, _M_contra, _T_co], exp: _E_contra, mod: _M_contra) -> _T_co: ...
1820 @overload
1821 def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ...
1822 @overload
1823 def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ...
1824
1825 quit: _sitebuiltins.Quitter
1826
1827 @disjoint_base
1828 class reversed(Generic[_T]):
1829 @overload
1830 def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
1831 @overload
1832 def __new__(cls, sequence: SupportsLenAndGetItem[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
1833 def __iter__(self) -> Self: ...
1834 def __next__(self) -> _T: ...
1835 def __length_hint__(self) -> int: ...
1836
1837 def repr(obj: object, /) -> str: ...
1838
1839 # See https://github.com/python/typeshed/pull/9141
1840 # and https://github.com/python/typeshed/pull/9151
1841 # on why we don't use `SupportsRound` from `typing.pyi`
1842
1843 @type_check_only
1844 class _SupportsRound1(Protocol[_T_co]):
1845 def __round__(self) -> _T_co: ...
1846
1847 @type_check_only
1848 class _SupportsRound2(Protocol[_T_co]):
1849 def __round__(self, ndigits: int, /) -> _T_co: ...
1850
1851 @overload
1852 def round(number: _SupportsRound1[_T], ndigits: None = None) -> _T: ...
1853 @overload
1854 def round(number: _SupportsRound2[_T], ndigits: SupportsIndex) -> _T: ...
1855
1856 # See https://github.com/python/typeshed/pull/6292#discussion_r748875189
1857 # for why arg 3 of `setattr` should be annotated with `Any` and not `object`
1858 def setattr(obj: object, name: str, value: Any, /) -> None: ...
1859 @overload
1860 def sorted(
1861 iterable: Iterable[SupportsRichComparisonT], /, *, key: None = None, reverse: bool = False
1862 ) -> list[SupportsRichComparisonT]: ...
1863 @overload
1864 def sorted(iterable: Iterable[_T], /, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = False) -> list[_T]: ...
1865
1866 _AddableT1 = TypeVar("_AddableT1", bound=SupportsAdd[Any, Any])
1867 _AddableT2 = TypeVar("_AddableT2", bound=SupportsAdd[Any, Any])
1868
1869 @type_check_only
1870 class _SupportsSumWithNoDefaultGiven(SupportsAdd[Any, Any], SupportsRAdd[int, Any], Protocol): ...
1871
1872 _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWithNoDefaultGiven)
1873
1874 # In general, the return type of `x + x` is *not* guaranteed to be the same type as x.
1875 # However, we can't express that in the stub for `sum()`
1876 # without creating many false-positive errors (see #7578).
1877 # Instead, we special-case the most common examples of this: bool and literal integers.
1878 @overload
1879 def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
1880 @overload
1881 def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
1882 @overload
1883 def sum(iterable: Iterable[_AddableT1], /, start: _AddableT2) -> _AddableT1 | _AddableT2: ...
1884
1885 # The argument to `vars()` has to have a `__dict__` attribute, so the second overload can't be annotated with `object`
1886 # (A "SupportsDunderDict" protocol doesn't work)
1887 @overload
1888 def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
1889 @overload
1890 def vars(object: Any = ..., /) -> dict[str, Any]: ...
1891 @disjoint_base
1892 class zip(Generic[_T_co]):
1893 if sys.version_info >= (3, 10):
1894 @overload
1895 def __new__(cls, *, strict: bool = False) -> zip[Any]: ...
1896 @overload
1897 def __new__(cls, iter1: Iterable[_T1], /, *, strict: bool = False) -> zip[tuple[_T1]]: ...
1898 @overload
1899 def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], /, *, strict: bool = False) -> zip[tuple[_T1, _T2]]: ...
1900 @overload
1901 def __new__(
1902 cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /, *, strict: bool = False
1903 ) -> zip[tuple[_T1, _T2, _T3]]: ...
1904 @overload
1905 def __new__(
1906 cls,
1907 iter1: Iterable[_T1],
1908 iter2: Iterable[_T2],
1909 iter3: Iterable[_T3],
1910 iter4: Iterable[_T4],
1911 /,
1912 *,
1913 strict: bool = False,
1914 ) -> zip[tuple[_T1, _T2, _T3, _T4]]: ...
1915 @overload
1916 def __new__(
1917 cls,
1918 iter1: Iterable[_T1],
1919 iter2: Iterable[_T2],
1920 iter3: Iterable[_T3],
1921 iter4: Iterable[_T4],
1922 iter5: Iterable[_T5],
1923 /,
1924 *,
1925 strict: bool = False,
1926 ) -> zip[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
1927 @overload
1928 def __new__(
1929 cls,
1930 iter1: Iterable[Any],
1931 iter2: Iterable[Any],
1932 iter3: Iterable[Any],
1933 iter4: Iterable[Any],
1934 iter5: Iterable[Any],
1935 iter6: Iterable[Any],
1936 /,
1937 *iterables: Iterable[Any],
1938 strict: bool = False,
1939 ) -> zip[tuple[Any, ...]]: ...
1940 else:
1941 @overload
1942 def __new__(cls) -> zip[Any]: ...
1943 @overload
1944 def __new__(cls, iter1: Iterable[_T1], /) -> zip[tuple[_T1]]: ...
1945 @overload
1946 def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], /) -> zip[tuple[_T1, _T2]]: ...
1947 @overload
1948 def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /) -> zip[tuple[_T1, _T2, _T3]]: ...
1949 @overload
1950 def __new__(
1951 cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], /
1952 ) -> zip[tuple[_T1, _T2, _T3, _T4]]: ...
1953 @overload
1954 def __new__(
1955 cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], iter5: Iterable[_T5], /
1956 ) -> zip[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
1957 @overload
1958 def __new__(
1959 cls,
1960 iter1: Iterable[Any],
1961 iter2: Iterable[Any],
1962 iter3: Iterable[Any],
1963 iter4: Iterable[Any],
1964 iter5: Iterable[Any],
1965 iter6: Iterable[Any],
1966 /,
1967 *iterables: Iterable[Any],
1968 ) -> zip[tuple[Any, ...]]: ...
1969
1970 def __iter__(self) -> Self: ...
1971 def __next__(self) -> _T_co: ...
1972
1973 # Signature of `builtins.__import__` should be kept identical to `importlib.__import__`
1974 # Return type of `__import__` should be kept the same as return type of `importlib.import_module`
1975 def __import__(
1976 name: str,
1977 globals: Mapping[str, object] | None = None,
1978 locals: Mapping[str, object] | None = None,
1979 fromlist: Sequence[str] | None = (),
1980 level: int = 0,
1981 ) -> types.ModuleType: ...
1982 def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...
1983
1984 if sys.version_info >= (3, 10):
1985 from types import EllipsisType, NotImplementedType
1986
1987 # Backwards compatibility hack for folks who relied on the ellipsis type
1988 # existing in typeshed in Python 3.9 and earlier.
1989 ellipsis = EllipsisType
1990
1991 Ellipsis: EllipsisType
1992 NotImplemented: NotImplementedType
1993 else:
1994 # Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
1995 # not exposed anywhere under that name, we make it private here.
1996 @final
1997 @type_check_only
1998 class ellipsis: ...
1999
2000 Ellipsis: ellipsis
2001
2002 @final
2003 @type_check_only
2004 class _NotImplementedType(Any): ...
2005
2006 NotImplemented: _NotImplementedType
2007
2008 @disjoint_base
2009 class BaseException:
2010 args: tuple[Any, ...]
2011 __cause__: BaseException | None
2012 __context__: BaseException | None
2013 __suppress_context__: bool
2014 __traceback__: TracebackType | None
2015 def __init__(self, *args: object) -> None: ...
2016 def __new__(cls, *args: Any, **kwds: Any) -> Self: ...
2017 def __setstate__(self, state: dict[str, Any] | None, /) -> None: ...
2018 def with_traceback(self, tb: TracebackType | None, /) -> Self: ...
2019 # Necessary for security-focused static analyzers (e.g, pysa)
2020 # See https://github.com/python/typeshed/pull/14900
2021 def __str__(self) -> str: ... # noqa: Y029
2022 def __repr__(self) -> str: ... # noqa: Y029
2023 if sys.version_info >= (3, 11):
2024 # only present after add_note() is called
2025 __notes__: list[str]
2026 def add_note(self, note: str, /) -> None: ...
2027
2028 class GeneratorExit(BaseException): ...
2029 class KeyboardInterrupt(BaseException): ...
2030
2031 @disjoint_base
2032 class SystemExit(BaseException):
2033 code: sys._ExitCode
2034
2035 class Exception(BaseException): ...
2036
2037 @disjoint_base
2038 class StopIteration(Exception):
2039 value: Any
2040
2041 @disjoint_base
2042 class OSError(Exception):
2043 errno: int | None
2044 strerror: str | None
2045 # filename, filename2 are actually str | bytes | None
2046 filename: Any
2047 filename2: Any
2048 if sys.platform == "win32":
2049 winerror: int
2050
2051 EnvironmentError = OSError
2052 IOError = OSError
2053 if sys.platform == "win32":
2054 WindowsError = OSError
2055
2056 class ArithmeticError(Exception): ...
2057 class AssertionError(Exception): ...
2058
2059 if sys.version_info >= (3, 10):
2060 @disjoint_base
2061 class AttributeError(Exception):
2062 def __init__(self, *args: object, name: str | None = None, obj: object = None) -> None: ...
2063 name: str | None
2064 obj: object
2065
2066 else:
2067 class AttributeError(Exception): ...
2068
2069 class BufferError(Exception): ...
2070 class EOFError(Exception): ...
2071
2072 @disjoint_base
2073 class ImportError(Exception):
2074 def __init__(self, *args: object, name: str | None = None, path: str | None = None) -> None: ...
2075 name: str | None
2076 path: str | None
2077 msg: str # undocumented
2078 if sys.version_info >= (3, 12):
2079 name_from: str | None # undocumented
2080
2081 class LookupError(Exception): ...
2082 class MemoryError(Exception): ...
2083
2084 if sys.version_info >= (3, 10):
2085 @disjoint_base
2086 class NameError(Exception):
2087 def __init__(self, *args: object, name: str | None = None) -> None: ...
2088 name: str | None
2089
2090 else:
2091 class NameError(Exception): ...
2092
2093 class ReferenceError(Exception): ...
2094 class RuntimeError(Exception): ...
2095 class StopAsyncIteration(Exception): ...
2096
2097 @disjoint_base
2098 class SyntaxError(Exception):
2099 msg: str
2100 filename: str | None
2101 lineno: int | None
2102 offset: int | None
2103 text: str | None
2104 # Errors are displayed differently if this attribute exists on the exception.
2105 # The value is always None.
2106 print_file_and_line: None
2107 if sys.version_info >= (3, 10):
2108 end_lineno: int | None
2109 end_offset: int | None
2110
2111 @overload
2112 def __init__(self) -> None: ...
2113 @overload
2114 def __init__(self, msg: object, /) -> None: ...
2115 # Second argument is the tuple (filename, lineno, offset, text)
2116 @overload
2117 def __init__(self, msg: str, info: tuple[str | None, int | None, int | None, str | None], /) -> None: ...
2118 if sys.version_info >= (3, 10):
2119 # end_lineno and end_offset must both be provided if one is.
2120 @overload
2121 def __init__(
2122 self, msg: str, info: tuple[str | None, int | None, int | None, str | None, int | None, int | None], /
2123 ) -> None: ...
2124 # If you provide more than two arguments, it still creates the SyntaxError, but
2125 # the arguments from the info tuple are not parsed. This form is omitted.
2126
2127 class SystemError(Exception): ...
2128 class TypeError(Exception): ...
2129 class ValueError(Exception): ...
2130 class FloatingPointError(ArithmeticError): ...
2131 class OverflowError(ArithmeticError): ...
2132 class ZeroDivisionError(ArithmeticError): ...
2133 class ModuleNotFoundError(ImportError): ...
2134 class IndexError(LookupError): ...
2135 class KeyError(LookupError): ...
2136 class UnboundLocalError(NameError): ...
2137
2138 class BlockingIOError(OSError):
2139 characters_written: int
2140
2141 class ChildProcessError(OSError): ...
2142 class ConnectionError(OSError): ...
2143 class BrokenPipeError(ConnectionError): ...
2144 class ConnectionAbortedError(ConnectionError): ...
2145 class ConnectionRefusedError(ConnectionError): ...
2146 class ConnectionResetError(ConnectionError): ...
2147 class FileExistsError(OSError): ...
2148 class FileNotFoundError(OSError): ...
2149 class InterruptedError(OSError): ...
2150 class IsADirectoryError(OSError): ...
2151 class NotADirectoryError(OSError): ...
2152 class PermissionError(OSError): ...
2153 class ProcessLookupError(OSError): ...
2154 class TimeoutError(OSError): ...
2155 class NotImplementedError(RuntimeError): ...
2156 class RecursionError(RuntimeError): ...
2157 class IndentationError(SyntaxError): ...
2158 class TabError(IndentationError): ...
2159 class UnicodeError(ValueError): ...
2160
2161 @disjoint_base
2162 class UnicodeDecodeError(UnicodeError):
2163 encoding: str
2164 object: bytes
2165 start: int
2166 end: int
2167 reason: str
2168 def __init__(self, encoding: str, object: ReadableBuffer, start: int, end: int, reason: str, /) -> None: ...
2169
2170 @disjoint_base
2171 class UnicodeEncodeError(UnicodeError):
2172 encoding: str
2173 object: str
2174 start: int
2175 end: int
2176 reason: str
2177 def __init__(self, encoding: str, object: str, start: int, end: int, reason: str, /) -> None: ...
2178
2179 @disjoint_base
2180 class UnicodeTranslateError(UnicodeError):
2181 encoding: None
2182 object: str
2183 start: int
2184 end: int
2185 reason: str
2186 def __init__(self, object: str, start: int, end: int, reason: str, /) -> None: ...
2187
2188 class Warning(Exception): ...
2189 class UserWarning(Warning): ...
2190 class DeprecationWarning(Warning): ...
2191 class SyntaxWarning(Warning): ...
2192 class RuntimeWarning(Warning): ...
2193 class FutureWarning(Warning): ...
2194 class PendingDeprecationWarning(Warning): ...
2195 class ImportWarning(Warning): ...
2196 class UnicodeWarning(Warning): ...
2197 class BytesWarning(Warning): ...
2198 class ResourceWarning(Warning): ...
2199
2200 if sys.version_info >= (3, 10):
2201 class EncodingWarning(Warning): ...
2202
2203 if sys.version_info >= (3, 11):
2204 _BaseExceptionT_co = TypeVar("_BaseExceptionT_co", bound=BaseException, covariant=True, default=BaseException)
2205 _BaseExceptionT = TypeVar("_BaseExceptionT", bound=BaseException)
2206 _ExceptionT_co = TypeVar("_ExceptionT_co", bound=Exception, covariant=True, default=Exception)
2207 _ExceptionT = TypeVar("_ExceptionT", bound=Exception)
2208
2209 # See `check_exception_group.py` for use-cases and comments.
2210 @disjoint_base
2211 class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
2212 def __new__(cls, message: str, exceptions: Sequence[_BaseExceptionT_co], /) -> Self: ...
2213 def __init__(self, message: str, exceptions: Sequence[_BaseExceptionT_co], /) -> None: ...
2214 @property
2215 def message(self) -> str: ...
2216 @property
2217 def exceptions(self) -> tuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]: ...
2218 @overload
2219 def subgroup(
2220 self, matcher_value: type[_ExceptionT] | tuple[type[_ExceptionT], ...], /
2221 ) -> ExceptionGroup[_ExceptionT] | None: ...
2222 @overload
2223 def subgroup(
2224 self, matcher_value: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...], /
2225 ) -> BaseExceptionGroup[_BaseExceptionT] | None: ...
2226 @overload
2227 def subgroup(
2228 self, matcher_value: Callable[[_BaseExceptionT_co | Self], bool], /
2229 ) -> BaseExceptionGroup[_BaseExceptionT_co] | None: ...
2230 @overload
2231 def split(
2232 self, matcher_value: type[_ExceptionT] | tuple[type[_ExceptionT], ...], /
2233 ) -> tuple[ExceptionGroup[_ExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]: ...
2234 @overload
2235 def split(
2236 self, matcher_value: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...], /
2237 ) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]: ...
2238 @overload
2239 def split(
2240 self, matcher_value: Callable[[_BaseExceptionT_co | Self], bool], /
2241 ) -> tuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]: ...
2242 # In reality it is `NonEmptySequence`:
2243 @overload
2244 def derive(self, excs: Sequence[_ExceptionT], /) -> ExceptionGroup[_ExceptionT]: ...
2245 @overload
2246 def derive(self, excs: Sequence[_BaseExceptionT], /) -> BaseExceptionGroup[_BaseExceptionT]: ...
2247 def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
2248
2249 class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception):
2250 def __new__(cls, message: str, exceptions: Sequence[_ExceptionT_co], /) -> Self: ...
2251 def __init__(self, message: str, exceptions: Sequence[_ExceptionT_co], /) -> None: ...
2252 @property
2253 def exceptions(self) -> tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]: ...
2254 # We accept a narrower type, but that's OK.
2255 @overload # type: ignore[override]
2256 def subgroup(
2257 self, matcher_value: type[_ExceptionT] | tuple[type[_ExceptionT], ...], /
2258 ) -> ExceptionGroup[_ExceptionT] | None: ...
2259 @overload
2260 def subgroup(
2261 self, matcher_value: Callable[[_ExceptionT_co | Self], bool], /
2262 ) -> ExceptionGroup[_ExceptionT_co] | None: ...
2263 @overload # type: ignore[override]
2264 def split(
2265 self, matcher_value: type[_ExceptionT] | tuple[type[_ExceptionT], ...], /
2266 ) -> tuple[ExceptionGroup[_ExceptionT] | None, ExceptionGroup[_ExceptionT_co] | None]: ...
2267 @overload
2268 def split(
2269 self, matcher_value: Callable[[_ExceptionT_co | Self], bool], /
2270 ) -> tuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]: ...
2271
2272 if sys.version_info >= (3, 13):
2273 class PythonFinalizationError(RuntimeError): ...