Skip to content

Commit 5c054c8

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@1d3c326
1 parent 761965d commit 5c054c8

18 files changed

Lines changed: 596 additions & 296 deletions

File tree

mypy/typeshed/stdlib/VERSIONS

Lines changed: 223 additions & 222 deletions
Large diffs are not rendered by default.

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ if sys.version_info >= (3, 10):
586586
patterns: list[pattern]
587587

588588
if sys.version_info >= (3, 12):
589-
class type_param(AST): ...
589+
class type_param(AST):
590+
end_lineno: int
591+
end_col_offset: int
590592

591593
class TypeVar(type_param):
592594
__match_args__ = ("name", "bound")

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ class Array(_CData, Generic[_CT]):
167167
def _type_(self) -> type[_CT]: ...
168168
@_type_.setter
169169
def _type_(self, value: type[_CT]) -> None: ...
170-
raw: bytes # Note: only available if _CT == c_char
170+
# Note: only available if _CT == c_char
171+
@property
172+
def raw(self) -> bytes: ...
173+
@raw.setter
174+
def raw(self, value: ReadableBuffer) -> None: ...
171175
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
172176
# TODO These methods cannot be annotated correctly at the moment.
173177
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/_thread.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ if sys.version_info >= (3, 8):
4646

4747
if sys.version_info >= (3, 12):
4848
def daemon_threads_allowed() -> bool: ...
49+
50+
class _local:
51+
def __getattribute__(self, __name: str) -> Any: ...
52+
def __setattr__(self, __name: str, __value: Any) -> None: ...
53+
def __delattr__(self, __name: str) -> None: ...

mypy/typeshed/stdlib/asyncore.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ if sys.platform != "win32":
8383
def write(self, data: bytes, flags: int = ...) -> int: ...
8484
def close(self) -> None: ...
8585
def fileno(self) -> int: ...
86+
def __del__(self) -> None: ...
8687

8788
class file_dispatcher(dispatcher):
8889
def __init__(self, fd: FileDescriptorLike, map: _MapType | None = None) -> None: ...

mypy/typeshed/stdlib/base64.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ if sys.version_info >= (3, 10):
2727
__all__ += ["b32hexencode", "b32hexdecode"]
2828

2929
def b64encode(s: ReadableBuffer, altchars: ReadableBuffer | None = None) -> bytes: ...
30-
def b64decode(s: str | ReadableBuffer, altchars: ReadableBuffer | None = None, validate: bool = False) -> bytes: ...
30+
def b64decode(s: str | ReadableBuffer, altchars: str | ReadableBuffer | None = None, validate: bool = False) -> bytes: ...
3131
def standard_b64encode(s: ReadableBuffer) -> bytes: ...
3232
def standard_b64decode(s: str | ReadableBuffer) -> bytes: ...
3333
def urlsafe_b64encode(s: ReadableBuffer) -> bytes: ...
3434
def urlsafe_b64decode(s: str | ReadableBuffer) -> bytes: ...
3535
def b32encode(s: ReadableBuffer) -> bytes: ...
36-
def b32decode(s: str | ReadableBuffer, casefold: bool = False, map01: bytes | None = None) -> bytes: ...
36+
def b32decode(s: str | ReadableBuffer, casefold: bool = False, map01: str | ReadableBuffer | None = None) -> bytes: ...
3737
def b16encode(s: ReadableBuffer) -> bytes: ...
3838
def b16decode(s: str | ReadableBuffer, casefold: bool = False) -> bytes: ...
3939

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ from typing import ( # noqa: Y022
5757
from typing_extensions import (
5858
Concatenate,
5959
Literal,
60+
LiteralString,
6061
ParamSpec,
6162
Self,
6263
SupportsIndex,
@@ -444,20 +445,38 @@ class str(Sequence[str]):
444445
def __new__(cls, object: object = ...) -> Self: ...
445446
@overload
446447
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
448+
@overload
449+
def capitalize(self: LiteralString) -> LiteralString: ...
450+
@overload
447451
def capitalize(self) -> str: ... # type: ignore[misc]
452+
@overload
453+
def casefold(self: LiteralString) -> LiteralString: ...
454+
@overload
448455
def casefold(self) -> str: ... # type: ignore[misc]
456+
@overload
457+
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
458+
@overload
449459
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
450460
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
451461
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
452462
def endswith(
453463
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
454464
) -> bool: ...
455465
if sys.version_info >= (3, 8):
466+
@overload
467+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
468+
@overload
456469
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
457470
else:
471+
@overload
472+
def expandtabs(self: LiteralString, tabsize: int = 8) -> LiteralString: ...
473+
@overload
458474
def expandtabs(self, tabsize: int = 8) -> str: ... # type: ignore[misc]
459475

460476
def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
477+
@overload
478+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
479+
@overload
461480
def format(self, *args: object, **kwargs: object) -> str: ...
462481
def format_map(self, map: _FormatMapMapping) -> str: ...
463482
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@@ -473,32 +492,91 @@ class str(Sequence[str]):
473492
def isspace(self) -> bool: ...
474493
def istitle(self) -> bool: ...
475494
def isupper(self) -> bool: ...
495+
@overload
496+
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
497+
@overload
476498
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
499+
@overload
500+
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
501+
@overload
477502
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
503+
@overload
504+
def lower(self: LiteralString) -> LiteralString: ...
505+
@overload
478506
def lower(self) -> str: ... # type: ignore[misc]
507+
@overload
508+
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
509+
@overload
479510
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
511+
@overload
512+
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
513+
@overload
480514
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
515+
@overload
516+
def replace(
517+
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
518+
) -> LiteralString: ...
519+
@overload
481520
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
482521
if sys.version_info >= (3, 9):
522+
@overload
523+
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
524+
@overload
483525
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
526+
@overload
527+
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
528+
@overload
484529
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]
485530

486531
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
487532
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
533+
@overload
534+
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
535+
@overload
488536
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
537+
@overload
538+
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
539+
@overload
489540
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
541+
@overload
542+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
543+
@overload
490544
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
545+
@overload
546+
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
547+
@overload
491548
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
549+
@overload
550+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
551+
@overload
492552
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
553+
@overload
554+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
555+
@overload
493556
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
494557
def startswith(
495558
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
496559
) -> bool: ...
560+
@overload
561+
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
562+
@overload
497563
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
564+
@overload
565+
def swapcase(self: LiteralString) -> LiteralString: ...
566+
@overload
498567
def swapcase(self) -> str: ... # type: ignore[misc]
568+
@overload
569+
def title(self: LiteralString) -> LiteralString: ...
570+
@overload
499571
def title(self) -> str: ... # type: ignore[misc]
500572
def translate(self, __table: _TranslateTable) -> str: ...
573+
@overload
574+
def upper(self: LiteralString) -> LiteralString: ...
575+
@overload
501576
def upper(self) -> str: ... # type: ignore[misc]
577+
@overload
578+
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
579+
@overload
502580
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
503581
@staticmethod
504582
@overload
@@ -509,6 +587,9 @@ class str(Sequence[str]):
509587
@staticmethod
510588
@overload
511589
def maketrans(__x: str, __y: str, __z: str) -> dict[int, int | None]: ...
590+
@overload
591+
def __add__(self: LiteralString, __value: LiteralString) -> LiteralString: ...
592+
@overload
512593
def __add__(self, __value: str) -> str: ... # type: ignore[misc]
513594
# Incompatible with Sequence.__contains__
514595
def __contains__(self, __key: str) -> bool: ... # type: ignore[override]
@@ -517,13 +598,25 @@ class str(Sequence[str]):
517598
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
518599
def __gt__(self, __value: str) -> bool: ...
519600
def __hash__(self) -> int: ...
601+
@overload
602+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
603+
@overload
520604
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
521605
def __le__(self, __value: str) -> bool: ...
522606
def __len__(self) -> int: ...
523607
def __lt__(self, __value: str) -> bool: ...
608+
@overload
609+
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
610+
@overload
524611
def __mod__(self, __value: Any) -> str: ...
612+
@overload
613+
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
614+
@overload
525615
def __mul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
526616
def __ne__(self, __value: object) -> bool: ...
617+
@overload
618+
def __rmul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
619+
@overload
527620
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
528621
def __getnewargs__(self) -> tuple[str]: ...
529622

@@ -1702,11 +1795,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
17021795
# Instead, we special-case the most common examples of this: bool and literal integers.
17031796
if sys.version_info >= (3, 8):
17041797
@overload
1705-
def sum(__iterable: Iterable[bool], start: int = 0) -> int: ... # type: ignore[overload-overlap]
1798+
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = 0) -> int: ... # type: ignore[overload-overlap]
17061799

17071800
else:
17081801
@overload
1709-
def sum(__iterable: Iterable[bool], __start: int = 0) -> int: ... # type: ignore[overload-overlap]
1802+
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = 0) -> int: ... # type: ignore[overload-overlap]
17101803

17111804
@overload
17121805
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...

mypy/typeshed/stdlib/concurrent/futures/process.pyi

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ from multiprocessing.context import BaseContext, Process
55
from multiprocessing.queues import Queue, SimpleQueue
66
from threading import Lock, Semaphore, Thread
77
from types import TracebackType
8-
from typing import Any, Generic, TypeVar
8+
from typing import Any, Generic, TypeVar, overload
9+
from typing_extensions import TypeVarTuple, Unpack
910
from weakref import ref
1011

1112
from ._base import BrokenExecutor, Executor, Future
1213

1314
_T = TypeVar("_T")
15+
_Ts = TypeVarTuple("_Ts")
1416

1517
_threads_wakeups: MutableMapping[Any, Any]
1618
_global_shutdown: bool
@@ -109,17 +111,17 @@ if sys.version_info >= (3, 11):
109111
def _process_worker(
110112
call_queue: Queue[_CallItem],
111113
result_queue: SimpleQueue[_ResultItem],
112-
initializer: Callable[..., object] | None,
113-
initargs: tuple[Any, ...],
114+
initializer: Callable[[Unpack[_Ts]], object] | None,
115+
initargs: tuple[Unpack[_Ts]],
114116
max_tasks: int | None = None,
115117
) -> None: ...
116118

117119
else:
118120
def _process_worker(
119121
call_queue: Queue[_CallItem],
120122
result_queue: SimpleQueue[_ResultItem],
121-
initializer: Callable[..., object] | None,
122-
initargs: tuple[Any, ...],
123+
initializer: Callable[[Unpack[_Ts]], object] | None,
124+
initargs: tuple[Unpack[_Ts]],
123125
) -> None: ...
124126

125127
if sys.version_info >= (3, 9):
@@ -169,22 +171,61 @@ class ProcessPoolExecutor(Executor):
169171
_result_queue: SimpleQueue[Any]
170172
_work_ids: Queue[Any]
171173
if sys.version_info >= (3, 11):
174+
@overload
172175
def __init__(
173176
self,
174177
max_workers: int | None = None,
175178
mp_context: BaseContext | None = None,
176-
initializer: Callable[..., object] | None = None,
177-
initargs: tuple[Any, ...] = (),
179+
initializer: Callable[[], object] | None = None,
180+
initargs: tuple[()] = (),
181+
*,
182+
max_tasks_per_child: int | None = None,
183+
) -> None: ...
184+
@overload
185+
def __init__(
186+
self,
187+
max_workers: int | None = None,
188+
mp_context: BaseContext | None = None,
189+
*,
190+
initializer: Callable[[Unpack[_Ts]], object],
191+
initargs: tuple[Unpack[_Ts]],
192+
max_tasks_per_child: int | None = None,
193+
) -> None: ...
194+
@overload
195+
def __init__(
196+
self,
197+
max_workers: int | None,
198+
mp_context: BaseContext | None,
199+
initializer: Callable[[Unpack[_Ts]], object],
200+
initargs: tuple[Unpack[_Ts]],
178201
*,
179202
max_tasks_per_child: int | None = None,
180203
) -> None: ...
181204
else:
205+
@overload
206+
def __init__(
207+
self,
208+
max_workers: int | None = None,
209+
mp_context: BaseContext | None = None,
210+
initializer: Callable[[], object] | None = None,
211+
initargs: tuple[()] = (),
212+
) -> None: ...
213+
@overload
182214
def __init__(
183215
self,
184216
max_workers: int | None = None,
185217
mp_context: BaseContext | None = None,
186-
initializer: Callable[..., object] | None = None,
187-
initargs: tuple[Any, ...] = (),
218+
*,
219+
initializer: Callable[[Unpack[_Ts]], object],
220+
initargs: tuple[Unpack[_Ts]],
221+
) -> None: ...
222+
@overload
223+
def __init__(
224+
self,
225+
max_workers: int | None,
226+
mp_context: BaseContext | None,
227+
initializer: Callable[[Unpack[_Ts]], object],
228+
initargs: tuple[Unpack[_Ts]],
188229
) -> None: ...
189230
if sys.version_info >= (3, 9):
190231
def _start_executor_manager_thread(self) -> None: ...

0 commit comments

Comments
 (0)