Skip to content

Commit e9cf866

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@48a0497
1 parent c26f129 commit e9cf866

39 files changed

Lines changed: 775 additions & 569 deletions

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PyCF_ONLY_AST: Literal[1024]
66
PyCF_TYPE_COMMENTS: Literal[4096]
77
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
88

9+
# Alias used for fields that must always be valid identifiers
10+
# A string `x` counts as a valid identifier if both the following are True
11+
# (1) `x.isidentifier()` evaluates to `True`
12+
# (2) `keyword.iskeyword(x)` evaluates to `False`
913
_Identifier: typing_extensions.TypeAlias = str
1014

1115
class AST:
@@ -499,7 +503,7 @@ class keyword(AST):
499503
class alias(AST):
500504
if sys.version_info >= (3, 10):
501505
__match_args__ = ("name", "asname")
502-
name: _Identifier
506+
name: str
503507
asname: _Identifier | None
504508

505509
class withitem(AST):

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/_curses.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,5 +553,6 @@ if sys.platform != "win32":
553553
major: int
554554
minor: int
555555
patch: int
556+
556557
ncurses_version: _ncurses_version
557558
window = _CursesWindow # undocumented

mypy/typeshed/stdlib/_msi.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if sys.platform == "win32":
4545
# Don't exist at runtime
4646
__new__: None # type: ignore[assignment]
4747
__init__: None # type: ignore[assignment]
48+
4849
def UuidCreate() -> str: ...
4950
def FCICreate(__cabname: str, __files: list[str]) -> None: ...
5051
def OpenDatabase(__path: str, __persist: int) -> _Database: ...

mypy/typeshed/stdlib/_thread.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def get_native_id() -> int: ... # only available on some platforms
3232
class _ExceptHookArgs(structseq[Any], tuple[type[BaseException], BaseException | None, TracebackType | None, Thread | None]):
3333
if sys.version_info >= (3, 10):
3434
__match_args__: Final = ("exc_type", "exc_value", "exc_traceback", "thread")
35+
3536
@property
3637
def exc_type(self) -> type[BaseException]: ...
3738
@property

mypy/typeshed/stdlib/asyncio/sslproto.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if sys.version_info >= (3, 11):
2525
STATE_CON_MADE: str
2626
STATE_EOF: str
2727
STATE_CON_LOST: str
28+
2829
def add_flowcontrol_defaults(high: int | None, low: int | None, kb: int) -> tuple[int, int]: ...
2930

3031
else:
@@ -155,9 +156,10 @@ class SSLProtocol(_SSLProtocolBase):
155156
def _check_handshake_timeout(self) -> None: ...
156157
def _on_handshake_complete(self, handshake_exc: BaseException | None) -> None: ...
157158
def _fatal_error(self, exc: BaseException, message: str = "Fatal error on transport") -> None: ...
158-
def _abort(self) -> None: ...
159159
if sys.version_info >= (3, 11):
160+
def _abort(self, exc: BaseException | None) -> None: ...
160161
def get_buffer(self, n: int) -> memoryview: ...
161162
else:
163+
def _abort(self) -> None: ...
162164
def _finalize(self) -> None: ...
163165
def _process_write_backlog(self) -> None: ...

mypy/typeshed/stdlib/asyncio/unix_events.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ if sys.platform != "win32":
9696
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
9797
def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ...
9898
def remove_child_handler(self, pid: int) -> bool: ...
99+
99100
else:
100101
class SafeChildWatcher(BaseChildWatcher):
101102
def __enter__(self) -> Self: ...
@@ -120,6 +121,7 @@ if sys.platform != "win32":
120121
else:
121122
def get_child_watcher(self) -> AbstractChildWatcher: ...
122123
def set_child_watcher(self, watcher: AbstractChildWatcher | None) -> None: ...
124+
123125
SelectorEventLoop = _UnixSelectorEventLoop
124126

125127
DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
@@ -136,6 +138,7 @@ if sys.platform != "win32":
136138
def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ...
137139
def remove_child_handler(self, pid: int) -> bool: ...
138140
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
141+
139142
else:
140143
class MultiLoopChildWatcher(AbstractChildWatcher):
141144
def is_active(self) -> bool: ...

mypy/typeshed/stdlib/asyncio/windows_events.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if sys.platform == "win32":
6969
def recvfrom_into(
7070
self, conn: socket.socket, buf: WriteableBuffer, flags: int = 0
7171
) -> futures.Future[tuple[int, socket._RetAddress]]: ...
72+
7273
SelectorEventLoop = _WindowsSelectorEventLoop
7374

7475
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
@@ -80,4 +81,5 @@ if sys.platform == "win32":
8081
_loop_factory: ClassVar[type[ProactorEventLoop]]
8182
def get_child_watcher(self) -> NoReturn: ...
8283
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
84+
8385
DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ from typing import ( # noqa: Y022
6161
from typing_extensions import ( # noqa: Y023
6262
Concatenate,
6363
Literal,
64+
LiteralString,
6465
ParamSpec,
6566
Self,
6667
TypeAlias,
@@ -434,16 +435,31 @@ class str(Sequence[str]):
434435
def __new__(cls, object: object = ...) -> Self: ...
435436
@overload
436437
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
438+
@overload
439+
def capitalize(self: LiteralString) -> LiteralString: ...
440+
@overload
437441
def capitalize(self) -> str: ... # type: ignore[misc]
442+
@overload
443+
def casefold(self: LiteralString) -> LiteralString: ...
444+
@overload
438445
def casefold(self) -> str: ... # type: ignore[misc]
446+
@overload
447+
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
448+
@overload
439449
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
440450
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
441451
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
442452
def endswith(
443453
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
444454
) -> bool: ...
455+
@overload
456+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
457+
@overload
445458
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
446459
def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
460+
@overload
461+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
462+
@overload
447463
def format(self, *args: object, **kwargs: object) -> str: ...
448464
def format_map(self, map: _FormatMapMapping) -> str: ...
449465
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@@ -459,32 +475,91 @@ class str(Sequence[str]):
459475
def isspace(self) -> bool: ...
460476
def istitle(self) -> bool: ...
461477
def isupper(self) -> bool: ...
478+
@overload
479+
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
480+
@overload
462481
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
482+
@overload
483+
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
484+
@overload
463485
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
486+
@overload
487+
def lower(self: LiteralString) -> LiteralString: ...
488+
@overload
464489
def lower(self) -> str: ... # type: ignore[misc]
490+
@overload
491+
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
492+
@overload
465493
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
494+
@overload
495+
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
496+
@overload
466497
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
498+
@overload
499+
def replace(
500+
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
501+
) -> LiteralString: ...
502+
@overload
467503
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
468504
if sys.version_info >= (3, 9):
505+
@overload
506+
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
507+
@overload
469508
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
509+
@overload
510+
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
511+
@overload
470512
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]
471513

472514
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
473515
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
516+
@overload
517+
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
518+
@overload
474519
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
520+
@overload
521+
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
522+
@overload
475523
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
524+
@overload
525+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
526+
@overload
476527
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
528+
@overload
529+
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
530+
@overload
477531
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
532+
@overload
533+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
534+
@overload
478535
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
536+
@overload
537+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
538+
@overload
479539
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
480540
def startswith(
481541
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
482542
) -> bool: ...
543+
@overload
544+
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
545+
@overload
483546
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
547+
@overload
548+
def swapcase(self: LiteralString) -> LiteralString: ...
549+
@overload
484550
def swapcase(self) -> str: ... # type: ignore[misc]
551+
@overload
552+
def title(self: LiteralString) -> LiteralString: ...
553+
@overload
485554
def title(self) -> str: ... # type: ignore[misc]
486555
def translate(self, __table: _TranslateTable) -> str: ...
556+
@overload
557+
def upper(self: LiteralString) -> LiteralString: ...
558+
@overload
487559
def upper(self) -> str: ... # type: ignore[misc]
560+
@overload
561+
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
562+
@overload
488563
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
489564
@staticmethod
490565
@overload
@@ -495,6 +570,9 @@ class str(Sequence[str]):
495570
@staticmethod
496571
@overload
497572
def maketrans(__x: str, __y: str, __z: str) -> dict[int, int | None]: ...
573+
@overload
574+
def __add__(self: LiteralString, __value: LiteralString) -> LiteralString: ...
575+
@overload
498576
def __add__(self, __value: str) -> str: ... # type: ignore[misc]
499577
# Incompatible with Sequence.__contains__
500578
def __contains__(self, __key: str) -> bool: ... # type: ignore[override]
@@ -503,13 +581,25 @@ class str(Sequence[str]):
503581
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
504582
def __gt__(self, __value: str) -> bool: ...
505583
def __hash__(self) -> int: ...
584+
@overload
585+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
586+
@overload
506587
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
507588
def __le__(self, __value: str) -> bool: ...
508589
def __len__(self) -> int: ...
509590
def __lt__(self, __value: str) -> bool: ...
591+
@overload
592+
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
593+
@overload
510594
def __mod__(self, __value: Any) -> str: ...
595+
@overload
596+
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
597+
@overload
511598
def __mul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
512599
def __ne__(self, __value: object) -> bool: ...
600+
@overload
601+
def __rmul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
602+
@overload
513603
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
514604
def __getnewargs__(self) -> tuple[str]: ...
515605

@@ -1590,7 +1680,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
15901680
# without creating many false-positive errors (see #7578).
15911681
# Instead, we special-case the most common examples of this: bool and literal integers.
15921682
@overload
1593-
def sum(__iterable: Iterable[bool], start: int = 0) -> int: ... # type: ignore[overload-overlap]
1683+
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = 0) -> int: ... # type: ignore[overload-overlap]
15941684
@overload
15951685
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...
15961686
@overload

mypy/typeshed/stdlib/calendar.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class HTMLCalendar(Calendar):
124124
def formatyear(self, theyear: int, width: int = 3) -> str: ...
125125
def formatyearpage(
126126
self, theyear: int, width: int = 3, css: str | None = "calendar.css", encoding: str | None = None
127-
) -> str: ...
127+
) -> bytes: ...
128128

129129
class different_locale:
130130
def __init__(self, locale: _LocaleType) -> None: ...
@@ -166,6 +166,7 @@ if sys.version_info >= (3, 12):
166166
OCTOBER: Literal[10]
167167
NOVEMBER: Literal[11]
168168
DECEMBER: Literal[12]
169+
169170
JANUARY = Month.JANUARY
170171
FEBRUARY = Month.FEBRUARY
171172
MARCH = Month.MARCH
@@ -187,6 +188,7 @@ if sys.version_info >= (3, 12):
187188
FRIDAY: Literal[4]
188189
SATURDAY: Literal[5]
189190
SUNDAY: Literal[6]
191+
190192
MONDAY = Day.MONDAY
191193
TUESDAY = Day.TUESDAY
192194
WEDNESDAY = Day.WEDNESDAY

0 commit comments

Comments
 (0)