Skip to content

Commit 7a3026d

Browse files
committed
Sync typeshed
Source commit: python/typeshed@5ebf892
1 parent ef3187a commit 7a3026d

File tree

3 files changed

+105
-13
lines changed

3 files changed

+105
-13
lines changed

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 95 additions & 3 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 Literal, Self, SupportsIndex, TypeAlias, TypeGuard, final
57+
from typing_extensions import Literal, LiteralString, Self, SupportsIndex, TypeAlias, TypeGuard, final
5858

5959
if sys.version_info >= (3, 9):
6060
from types import GenericAlias
@@ -413,20 +413,38 @@ class str(Sequence[str]):
413413
def __new__(cls, object: object = ...) -> Self: ...
414414
@overload
415415
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
416+
@overload
417+
def capitalize(self: LiteralString) -> LiteralString: ...
418+
@overload
416419
def capitalize(self) -> str: ... # type: ignore[misc]
420+
@overload
421+
def casefold(self: LiteralString) -> LiteralString: ...
422+
@overload
417423
def casefold(self) -> str: ... # type: ignore[misc]
424+
@overload
425+
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
426+
@overload
418427
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
419428
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
420429
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
421430
def endswith(
422431
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
423432
) -> bool: ...
424433
if sys.version_info >= (3, 8):
434+
@overload
435+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
436+
@overload
425437
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
426438
else:
439+
@overload
440+
def expandtabs(self: LiteralString, tabsize: int = 8) -> LiteralString: ...
441+
@overload
427442
def expandtabs(self, tabsize: int = 8) -> str: ... # type: ignore[misc]
428443

429444
def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
445+
@overload
446+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
447+
@overload
430448
def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore[misc]
431449
def format_map(self, map: _FormatMapMapping) -> str: ...
432450
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@@ -442,32 +460,91 @@ class str(Sequence[str]):
442460
def isspace(self) -> bool: ...
443461
def istitle(self) -> bool: ...
444462
def isupper(self) -> bool: ...
463+
@overload
464+
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
465+
@overload
445466
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
467+
@overload
468+
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
469+
@overload
446470
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
471+
@overload
472+
def lower(self: LiteralString) -> LiteralString: ...
473+
@overload
447474
def lower(self) -> str: ... # type: ignore[misc]
475+
@overload
476+
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
477+
@overload
448478
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
479+
@overload
480+
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
481+
@overload
449482
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
483+
@overload
484+
def replace(
485+
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
486+
) -> LiteralString: ...
487+
@overload
450488
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
451489
if sys.version_info >= (3, 9):
490+
@overload
491+
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
492+
@overload
452493
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
494+
@overload
495+
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
496+
@overload
453497
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]
454498

455499
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
456500
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
501+
@overload
502+
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
503+
@overload
457504
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
505+
@overload
506+
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
507+
@overload
458508
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
509+
@overload
510+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
511+
@overload
459512
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
513+
@overload
514+
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
515+
@overload
460516
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
517+
@overload
518+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
519+
@overload
461520
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
521+
@overload
522+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
523+
@overload
462524
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
463525
def startswith(
464526
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
465527
) -> bool: ...
528+
@overload
529+
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
530+
@overload
466531
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
532+
@overload
533+
def swapcase(self: LiteralString) -> LiteralString: ...
534+
@overload
467535
def swapcase(self) -> str: ... # type: ignore[misc]
536+
@overload
537+
def title(self: LiteralString) -> LiteralString: ...
538+
@overload
468539
def title(self) -> str: ... # type: ignore[misc]
469540
def translate(self, __table: _TranslateTable) -> str: ...
541+
@overload
542+
def upper(self: LiteralString) -> LiteralString: ...
543+
@overload
470544
def upper(self) -> str: ... # type: ignore[misc]
545+
@overload
546+
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
547+
@overload
471548
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
472549
@staticmethod
473550
@overload
@@ -478,20 +555,35 @@ class str(Sequence[str]):
478555
@staticmethod
479556
@overload
480557
def maketrans(__x: str, __y: str, __z: str) -> dict[int, int | None]: ...
558+
@overload
559+
def __add__(self: LiteralString, __s: LiteralString) -> LiteralString: ...
560+
@overload
481561
def __add__(self, __s: str) -> str: ... # type: ignore[misc]
482562
# Incompatible with Sequence.__contains__
483563
def __contains__(self, __o: str) -> bool: ... # type: ignore[override]
484564
def __eq__(self, __x: object) -> bool: ...
485565
def __ge__(self, __x: str) -> bool: ...
486566
def __getitem__(self, __i: SupportsIndex | slice) -> str: ...
487567
def __gt__(self, __x: str) -> bool: ...
568+
@overload
569+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
570+
@overload
488571
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
489572
def __le__(self, __x: str) -> bool: ...
490573
def __len__(self) -> int: ...
491574
def __lt__(self, __x: str) -> bool: ...
575+
@overload
576+
def __mod__(self: LiteralString, __x: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
577+
@overload
492578
def __mod__(self, __x: Any) -> str: ... # type: ignore[misc]
579+
@overload
580+
def __mul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ...
581+
@overload
493582
def __mul__(self, __n: SupportsIndex) -> str: ... # type: ignore[misc]
494583
def __ne__(self, __x: object) -> bool: ...
584+
@overload
585+
def __rmul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ...
586+
@overload
495587
def __rmul__(self, __n: SupportsIndex) -> str: ... # type: ignore[misc]
496588
def __getnewargs__(self) -> tuple[str]: ...
497589

@@ -1634,11 +1726,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
16341726
# Instead, we special-case the most common examples of this: bool and literal integers.
16351727
if sys.version_info >= (3, 8):
16361728
@overload
1637-
def sum(__iterable: Iterable[bool], start: int = 0) -> int: ... # type: ignore[misc]
1729+
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = 0) -> int: ... # type: ignore[misc]
16381730

16391731
else:
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
@overload
16441736
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...

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

mypy/typeshed/stdlib/urllib/parse.pyi

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,22 @@ def urljoin(base: AnyStr, url: AnyStr | None, allow_fragments: bool = True) -> A
192192
@overload
193193
def urlparse(url: str, scheme: str = "", allow_fragments: bool = True) -> ParseResult: ...
194194
@overload
195-
def urlparse(url: bytes | bytearray, scheme: bytes | bytearray | None, allow_fragments: bool = True) -> ParseResultBytes: ...
196-
@overload
197195
def urlparse(
198-
url: None, scheme: bytes | bytearray | None | Literal[""] = "", allow_fragments: bool = True
196+
url: bytes | bytearray | None, scheme: bytes | bytearray | None | Literal[""] = "", allow_fragments: bool = True
199197
) -> ParseResultBytes: ...
200198
@overload
201199
def urlsplit(url: str, scheme: str = "", allow_fragments: bool = True) -> SplitResult: ...
202200

203201
if sys.version_info >= (3, 11):
204202
@overload
205-
def urlsplit(url: bytes, scheme: bytes | None, allow_fragments: bool = True) -> SplitResultBytes: ...
206-
@overload
207-
def urlsplit(url: None, scheme: bytes | None | Literal[""] = "", allow_fragments: bool = True) -> SplitResultBytes: ...
203+
def urlsplit(
204+
url: bytes | None, scheme: bytes | None | Literal[""] = "", allow_fragments: bool = True
205+
) -> SplitResultBytes: ...
208206

209207
else:
210-
@overload
211-
def urlsplit(url: bytes | bytearray, scheme: bytes | bytearray | None, allow_fragments: bool = True) -> SplitResultBytes: ...
212208
@overload
213209
def urlsplit(
214-
url: None, scheme: bytes | bytearray | None | Literal[""] = "", allow_fragments: bool = True
210+
url: bytes | bytearray | None, scheme: bytes | bytearray | None | Literal[""] = "", allow_fragments: bool = True
215211
) -> SplitResultBytes: ...
216212

217213
@overload

0 commit comments

Comments
 (0)