Skip to content

Commit 5a57764

Browse files
AlexWaygoodJelleZijlstra
authored andcommitted
Sync typeshed
Source commit: python/typeshed@6fd245d
1 parent 89469ac commit 5a57764

Some content is hidden

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

83 files changed

+1118
-937
lines changed

mypy/typeshed/stdlib/_compression.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DecompressReader(RawIOBase):
1717
self,
1818
fp: _Reader,
1919
decomp_factory: Callable[..., object],
20-
trailing_error: type[Exception] | tuple[type[Exception], ...] = ...,
20+
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
2121
**decomp_args: Any,
2222
) -> None: ...
2323
def readinto(self, b: WriteableBuffer) -> int: ...

mypy/typeshed/stdlib/_dummy_thread.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ __all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "i
77
TIMEOUT_MAX: int
88
error = RuntimeError
99

10-
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = ...) -> None: ...
10+
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any] = {}) -> None: ...
1111
def exit() -> NoReturn: ...
1212
def get_ident() -> int: ...
1313
def allocate_lock() -> LockType: ...

mypy/typeshed/stdlib/_dummy_threading.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Thread:
6262
group: None = None,
6363
target: Callable[..., object] | None = None,
6464
name: str | None = None,
65-
args: Iterable[Any] = ...,
65+
args: Iterable[Any] = (),
6666
kwargs: Mapping[str, Any] | None = None,
6767
*,
6868
daemon: bool | None = None,

mypy/typeshed/stdlib/_sitebuiltins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Quitter:
1010

1111
class _Printer:
1212
MAXLINES: ClassVar[Literal[23]]
13-
def __init__(self, name: str, data: str, files: Iterable[str] = ..., dirs: Iterable[str] = ...) -> None: ...
13+
def __init__(self, name: str, data: str, files: Iterable[str] = (), dirs: Iterable[str] = ()) -> None: ...
1414
def __call__(self) -> None: ...
1515

1616
class _Helper:

mypy/typeshed/stdlib/_winapi.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ if sys.platform == "win32":
5454
HIGH_PRIORITY_CLASS: Literal[0x80]
5555
INFINITE: Literal[0xFFFFFFFF]
5656
if sys.version_info >= (3, 8):
57-
INVALID_HANDLE_VALUE: Literal[0xFFFFFFFFFFFFFFFF]
57+
# Ignore the flake8 error -- flake8-pyi assumes
58+
# most numbers this long will be implementation details,
59+
# but here we can see that it's a power of 2
60+
INVALID_HANDLE_VALUE: Literal[0xFFFFFFFFFFFFFFFF] # noqa: Y054
5861
IDLE_PRIORITY_CLASS: Literal[0x40]
5962
NORMAL_PRIORITY_CLASS: Literal[0x20]
6063
REALTIME_PRIORITY_CLASS: Literal[0x100]

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
135135
usage: str | None = None,
136136
description: str | None = None,
137137
epilog: str | None = None,
138-
parents: Sequence[ArgumentParser] = ...,
138+
parents: Sequence[ArgumentParser] = [],
139139
formatter_class: _FormatterClass = ...,
140140
prefix_chars: str = "-",
141141
fromfile_prefix_chars: str | None = None,
@@ -152,7 +152,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
152152
usage: str | None = None,
153153
description: str | None = None,
154154
epilog: str | None = None,
155-
parents: Sequence[ArgumentParser] = ...,
155+
parents: Sequence[ArgumentParser] = [],
156156
formatter_class: _FormatterClass = ...,
157157
prefix_chars: str = "-",
158158
fromfile_prefix_chars: str | None = None,

mypy/typeshed/stdlib/asyncio/windows_utils.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if sys.platform == "win32":
1515
BUFSIZE: Literal[8192]
1616
PIPE = subprocess.PIPE
1717
STDOUT = subprocess.STDOUT
18-
def pipe(*, duplex: bool = False, overlapped: tuple[bool, bool] = ..., bufsize: int = 8192) -> tuple[int, int]: ...
18+
def pipe(*, duplex: bool = False, overlapped: tuple[bool, bool] = (True, True), bufsize: int = 8192) -> tuple[int, int]: ...
1919

2020
class PipeHandle:
2121
def __init__(self, handle: int) -> None: ...

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ from typing import ( # noqa: Y022
5454
overload,
5555
type_check_only,
5656
)
57-
from typing_extensions import Concatenate, Literal, ParamSpec, Self, SupportsIndex, TypeAlias, TypeGuard, final
57+
from typing_extensions import Concatenate, Literal, LiteralString, ParamSpec, Self, SupportsIndex, TypeAlias, TypeGuard, final
5858

5959
if sys.version_info >= (3, 9):
6060
from types import GenericAlias
@@ -416,20 +416,38 @@ class str(Sequence[str]):
416416
def __new__(cls, object: object = ...) -> Self: ...
417417
@overload
418418
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
419+
@overload
420+
def capitalize(self: LiteralString) -> LiteralString: ...
421+
@overload
419422
def capitalize(self) -> str: ... # type: ignore[misc]
423+
@overload
424+
def casefold(self: LiteralString) -> LiteralString: ...
425+
@overload
420426
def casefold(self) -> str: ... # type: ignore[misc]
427+
@overload
428+
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
429+
@overload
421430
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
422431
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
423432
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
424433
def endswith(
425434
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
426435
) -> bool: ...
427436
if sys.version_info >= (3, 8):
437+
@overload
438+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
439+
@overload
428440
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
429441
else:
442+
@overload
443+
def expandtabs(self: LiteralString, tabsize: int = 8) -> LiteralString: ...
444+
@overload
430445
def expandtabs(self, tabsize: int = 8) -> str: ... # type: ignore[misc]
431446

432447
def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
448+
@overload
449+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
450+
@overload
433451
def format(self, *args: object, **kwargs: object) -> str: ...
434452
def format_map(self, map: _FormatMapMapping) -> str: ...
435453
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@@ -445,32 +463,91 @@ class str(Sequence[str]):
445463
def isspace(self) -> bool: ...
446464
def istitle(self) -> bool: ...
447465
def isupper(self) -> bool: ...
466+
@overload
467+
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
468+
@overload
448469
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
470+
@overload
471+
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
472+
@overload
449473
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
474+
@overload
475+
def lower(self: LiteralString) -> LiteralString: ...
476+
@overload
450477
def lower(self) -> str: ... # type: ignore[misc]
478+
@overload
479+
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
480+
@overload
451481
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
482+
@overload
483+
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
484+
@overload
452485
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
486+
@overload
487+
def replace(
488+
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
489+
) -> LiteralString: ...
490+
@overload
453491
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
454492
if sys.version_info >= (3, 9):
493+
@overload
494+
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
495+
@overload
455496
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
497+
@overload
498+
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
499+
@overload
456500
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]
457501

458502
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
459503
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
504+
@overload
505+
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
506+
@overload
460507
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
508+
@overload
509+
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
510+
@overload
461511
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
512+
@overload
513+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
514+
@overload
462515
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
516+
@overload
517+
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
518+
@overload
463519
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
520+
@overload
521+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
522+
@overload
464523
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
524+
@overload
525+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
526+
@overload
465527
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
466528
def startswith(
467529
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
468530
) -> bool: ...
531+
@overload
532+
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
533+
@overload
469534
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
535+
@overload
536+
def swapcase(self: LiteralString) -> LiteralString: ...
537+
@overload
470538
def swapcase(self) -> str: ... # type: ignore[misc]
539+
@overload
540+
def title(self: LiteralString) -> LiteralString: ...
541+
@overload
471542
def title(self) -> str: ... # type: ignore[misc]
472543
def translate(self, __table: _TranslateTable) -> str: ...
544+
@overload
545+
def upper(self: LiteralString) -> LiteralString: ...
546+
@overload
473547
def upper(self) -> str: ... # type: ignore[misc]
548+
@overload
549+
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
550+
@overload
474551
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
475552
@staticmethod
476553
@overload
@@ -481,20 +558,35 @@ class str(Sequence[str]):
481558
@staticmethod
482559
@overload
483560
def maketrans(__x: str, __y: str, __z: str) -> dict[int, int | None]: ...
561+
@overload
562+
def __add__(self: LiteralString, __value: LiteralString) -> LiteralString: ...
563+
@overload
484564
def __add__(self, __value: str) -> str: ... # type: ignore[misc]
485565
# Incompatible with Sequence.__contains__
486566
def __contains__(self, __key: str) -> bool: ... # type: ignore[override]
487567
def __eq__(self, __value: object) -> bool: ...
488568
def __ge__(self, __value: str) -> bool: ...
489569
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
490570
def __gt__(self, __value: str) -> bool: ...
571+
@overload
572+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
573+
@overload
491574
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
492575
def __le__(self, __value: str) -> bool: ...
493576
def __len__(self) -> int: ...
494577
def __lt__(self, __value: str) -> bool: ...
578+
@overload
579+
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
580+
@overload
495581
def __mod__(self, __value: Any) -> str: ...
582+
@overload
583+
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
584+
@overload
496585
def __mul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
497586
def __ne__(self, __value: object) -> bool: ...
587+
@overload
588+
def __rmul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
589+
@overload
498590
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
499591
def __getnewargs__(self) -> tuple[str]: ...
500592

@@ -1638,11 +1730,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
16381730
# Instead, we special-case the most common examples of this: bool and literal integers.
16391731
if sys.version_info >= (3, 8):
16401732
@overload
1641-
def sum(__iterable: Iterable[bool], start: int = 0) -> int: ... # type: ignore[misc]
1733+
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = 0) -> int: ... # type: ignore[misc]
16421734

16431735
else:
16441736
@overload
1645-
def sum(__iterable: Iterable[bool], __start: int = 0) -> int: ... # type: ignore[misc]
1737+
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = 0) -> int: ... # type: ignore[misc]
16461738

16471739
@overload
16481740
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...
@@ -1747,7 +1839,7 @@ def __import__(
17471839
name: str,
17481840
globals: Mapping[str, object] | None = None,
17491841
locals: Mapping[str, object] | None = None,
1750-
fromlist: Sequence[str] = ...,
1842+
fromlist: Sequence[str] = (),
17511843
level: int = 0,
17521844
) -> types.ModuleType: ...
17531845
def __build_class__(__func: Callable[[], _Cell | Any], __name: str, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def _chain_from_iterable_of_lists(iterable: Iterable[MutableSequence[Any]]) -> A
153153
class BrokenProcessPool(BrokenExecutor): ...
154154

155155
class ProcessPoolExecutor(Executor):
156-
_mp_context: BaseContext | None = ...
157-
_initializer: Callable[..., None] | None = ...
158-
_initargs: tuple[Any, ...] = ...
156+
_mp_context: BaseContext | None
157+
_initializer: Callable[..., None] | None
158+
_initargs: tuple[Any, ...]
159159
_executor_manager_thread: _ThreadWakeup
160160
_processes: MutableMapping[int, Process]
161161
_shutdown_thread: bool
@@ -174,7 +174,7 @@ class ProcessPoolExecutor(Executor):
174174
max_workers: int | None = None,
175175
mp_context: BaseContext | None = None,
176176
initializer: Callable[..., object] | None = None,
177-
initargs: tuple[Any, ...] = ...,
177+
initargs: tuple[Any, ...] = (),
178178
*,
179179
max_tasks_per_child: int | None = None,
180180
) -> None: ...
@@ -184,7 +184,7 @@ class ProcessPoolExecutor(Executor):
184184
max_workers: int | None = None,
185185
mp_context: BaseContext | None = None,
186186
initializer: Callable[..., object] | None = None,
187-
initargs: tuple[Any, ...] = ...,
187+
initargs: tuple[Any, ...] = (),
188188
) -> None: ...
189189
if sys.version_info >= (3, 9):
190190
def _start_executor_manager_thread(self) -> None: ...

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ class ThreadPoolExecutor(Executor):
4444
_broken: bool
4545
_shutdown: bool
4646
_shutdown_lock: Lock
47-
_thread_name_prefix: str | None = ...
48-
_initializer: Callable[..., None] | None = ...
49-
_initargs: tuple[Any, ...] = ...
47+
_thread_name_prefix: str | None
48+
_initializer: Callable[..., None] | None
49+
_initargs: tuple[Any, ...]
5050
_work_queue: queue.SimpleQueue[_WorkItem[Any]]
5151
def __init__(
5252
self,
5353
max_workers: int | None = None,
5454
thread_name_prefix: str = "",
5555
initializer: Callable[..., object] | None = None,
56-
initargs: tuple[Any, ...] = ...,
56+
initargs: tuple[Any, ...] = (),
5757
) -> None: ...
5858
def _adjust_thread_count(self) -> None: ...
5959
def _initializer_failed(self) -> None: ...

mypy/typeshed/stdlib/configparser.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class RawConfigParser(_Parser):
6969
dict_type: type[Mapping[str, str]] = ...,
7070
*,
7171
allow_no_value: Literal[True],
72-
delimiters: Sequence[str] = ...,
73-
comment_prefixes: Sequence[str] = ...,
72+
delimiters: Sequence[str] = ("=", ":"),
73+
comment_prefixes: Sequence[str] = ("#", ";"),
7474
inline_comment_prefixes: Sequence[str] | None = None,
7575
strict: bool = True,
7676
empty_lines_in_values: bool = True,
@@ -85,8 +85,8 @@ class RawConfigParser(_Parser):
8585
dict_type: type[Mapping[str, str]],
8686
allow_no_value: Literal[True],
8787
*,
88-
delimiters: Sequence[str] = ...,
89-
comment_prefixes: Sequence[str] = ...,
88+
delimiters: Sequence[str] = ("=", ":"),
89+
comment_prefixes: Sequence[str] = ("#", ";"),
9090
inline_comment_prefixes: Sequence[str] | None = None,
9191
strict: bool = True,
9292
empty_lines_in_values: bool = True,
@@ -101,8 +101,8 @@ class RawConfigParser(_Parser):
101101
dict_type: type[Mapping[str, str]] = ...,
102102
allow_no_value: bool = False,
103103
*,
104-
delimiters: Sequence[str] = ...,
105-
comment_prefixes: Sequence[str] = ...,
104+
delimiters: Sequence[str] = ("=", ":"),
105+
comment_prefixes: Sequence[str] = ("#", ";"),
106106
inline_comment_prefixes: Sequence[str] | None = None,
107107
strict: bool = True,
108108
empty_lines_in_values: bool = True,

mypy/typeshed/stdlib/copy.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ _T = TypeVar("_T")
88
PyStringMap: Any
99

1010
# Note: memo and _nil are internal kwargs.
11-
def deepcopy(x: _T, memo: dict[int, Any] | None = None, _nil: Any = ...) -> _T: ...
11+
def deepcopy(x: _T, memo: dict[int, Any] | None = None, _nil: Any = []) -> _T: ...
1212
def copy(x: _T) -> _T: ...
1313

1414
class Error(Exception): ...

mypy/typeshed/stdlib/ctypes/__init__.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ class Array(Generic[_CT], _CData):
271271
def _type_(self) -> type[_CT]: ...
272272
@_type_.setter
273273
def _type_(self, value: type[_CT]) -> None: ...
274-
raw: bytes # Note: only available if _CT == c_char
274+
# Note: only available if _CT == c_char
275+
@property
276+
def raw(self) -> bytes: ...
277+
@raw.setter
278+
def raw(self, value: ReadableBuffer) -> None: ...
275279
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
276280
# TODO These methods cannot be annotated correctly at the moment.
277281
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

0 commit comments

Comments
 (0)