Skip to content

Commit d7f9f06

Browse files
AlexWaygoodhauntsaninja
authored andcommitted
Sync typeshed
Source commit: python/typeshed@a83e559
1 parent 14743a1 commit d7f9f06

25 files changed

+264
-73
lines changed

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ class Array(Generic[_CT], _CData):
151151
def _type_(self) -> type[_CT]: ...
152152
@_type_.setter
153153
def _type_(self, value: type[_CT]) -> None: ...
154-
raw: bytes # Note: only available if _CT == c_char
154+
# Note: only available if _CT == c_char
155+
@property
156+
def raw(self) -> bytes: ...
157+
@raw.setter
158+
def raw(self, value: ReadableBuffer) -> None: ...
155159
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
156160
# TODO These methods cannot be annotated correctly at the moment.
157161
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/_decimal.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Decimal:
7373
def from_float(cls, __f: float) -> Self: ...
7474
def __bool__(self) -> bool: ...
7575
def compare(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
76+
def __hash__(self) -> int: ...
7677
def as_tuple(self) -> DecimalTuple: ...
7778
def as_integer_ratio(self) -> tuple[int, int]: ...
7879
def to_eng_string(self, context: Context | None = None) -> str: ...

mypy/typeshed/stdlib/_weakref.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ReferenceType(Generic[_T]):
2222
__callback__: Callable[[ReferenceType[_T]], Any]
2323
def __new__(cls, __o: _T, __callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
2424
def __call__(self) -> _T | None: ...
25+
def __hash__(self) -> int: ...
2526
if sys.version_info >= (3, 9):
2627
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
2728

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class TimerHandle(Handle):
8686
loop: AbstractEventLoop,
8787
context: Context | None = None,
8888
) -> None: ...
89+
def __hash__(self) -> int: ...
8990
def when(self) -> float: ...
9091
def __lt__(self, other: TimerHandle) -> bool: ...
9192
def __le__(self, other: TimerHandle) -> bool: ...

mypy/typeshed/stdlib/asyncio/taskgroups.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# This only exists in 3.11+. See VERSIONS.
2-
1+
import sys
32
from contextvars import Context
43
from types import TracebackType
54
from typing import TypeVar
@@ -8,7 +7,10 @@ from typing_extensions import Self
87
from . import _CoroutineLike
98
from .tasks import Task
109

11-
__all__ = ["TaskGroup"]
10+
if sys.version_info >= (3, 12):
11+
__all__ = ("TaskGroup",)
12+
else:
13+
__all__ = ["TaskGroup"]
1214

1315
_T = TypeVar("_T")
1416

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ from typing import ( # noqa: Y022
5656
from typing_extensions import (
5757
Concatenate,
5858
Literal,
59+
LiteralString,
5960
ParamSpec,
6061
Self,
6162
SupportsIndex,
@@ -315,6 +316,7 @@ class int:
315316
def __float__(self) -> float: ...
316317
def __int__(self) -> int: ...
317318
def __abs__(self) -> int: ...
319+
def __hash__(self) -> int: ...
318320
def __bool__(self) -> bool: ...
319321
def __index__(self) -> int: ...
320322

@@ -378,6 +380,7 @@ class float:
378380
def __int__(self) -> int: ...
379381
def __float__(self) -> float: ...
380382
def __abs__(self) -> float: ...
383+
def __hash__(self) -> int: ...
381384
def __bool__(self) -> bool: ...
382385

383386
class complex:
@@ -417,6 +420,7 @@ class complex:
417420
def __neg__(self) -> complex: ...
418421
def __pos__(self) -> complex: ...
419422
def __abs__(self) -> float: ...
423+
def __hash__(self) -> int: ...
420424
def __bool__(self) -> bool: ...
421425
if sys.version_info >= (3, 11):
422426
def __complex__(self) -> complex: ...
@@ -432,20 +436,38 @@ class str(Sequence[str]):
432436
def __new__(cls, object: object = ...) -> Self: ...
433437
@overload
434438
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
439+
@overload
440+
def capitalize(self: LiteralString) -> LiteralString: ...
441+
@overload
435442
def capitalize(self) -> str: ... # type: ignore[misc]
443+
@overload
444+
def casefold(self: LiteralString) -> LiteralString: ...
445+
@overload
436446
def casefold(self) -> str: ... # type: ignore[misc]
447+
@overload
448+
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
449+
@overload
437450
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
438451
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
439452
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
440453
def endswith(
441454
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
442455
) -> bool: ...
443456
if sys.version_info >= (3, 8):
457+
@overload
458+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
459+
@overload
444460
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
445461
else:
462+
@overload
463+
def expandtabs(self: LiteralString, tabsize: int = 8) -> LiteralString: ...
464+
@overload
446465
def expandtabs(self, tabsize: int = 8) -> str: ... # type: ignore[misc]
447466

448467
def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
468+
@overload
469+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
470+
@overload
449471
def format(self, *args: object, **kwargs: object) -> str: ...
450472
def format_map(self, map: _FormatMapMapping) -> str: ...
451473
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@@ -461,32 +483,91 @@ class str(Sequence[str]):
461483
def isspace(self) -> bool: ...
462484
def istitle(self) -> bool: ...
463485
def isupper(self) -> bool: ...
486+
@overload
487+
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
488+
@overload
464489
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
490+
@overload
491+
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
492+
@overload
465493
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
494+
@overload
495+
def lower(self: LiteralString) -> LiteralString: ...
496+
@overload
466497
def lower(self) -> str: ... # type: ignore[misc]
498+
@overload
499+
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
500+
@overload
467501
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
502+
@overload
503+
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
504+
@overload
468505
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
506+
@overload
507+
def replace(
508+
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
509+
) -> LiteralString: ...
510+
@overload
469511
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
470512
if sys.version_info >= (3, 9):
513+
@overload
514+
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
515+
@overload
471516
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
517+
@overload
518+
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
519+
@overload
472520
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]
473521

474522
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
475523
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
524+
@overload
525+
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
526+
@overload
476527
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
528+
@overload
529+
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
530+
@overload
477531
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
532+
@overload
533+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
534+
@overload
478535
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
536+
@overload
537+
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
538+
@overload
479539
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
540+
@overload
541+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
542+
@overload
480543
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
544+
@overload
545+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
546+
@overload
481547
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
482548
def startswith(
483549
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
484550
) -> bool: ...
551+
@overload
552+
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
553+
@overload
485554
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
555+
@overload
556+
def swapcase(self: LiteralString) -> LiteralString: ...
557+
@overload
486558
def swapcase(self) -> str: ... # type: ignore[misc]
559+
@overload
560+
def title(self: LiteralString) -> LiteralString: ...
561+
@overload
487562
def title(self) -> str: ... # type: ignore[misc]
488563
def translate(self, __table: _TranslateTable) -> str: ...
564+
@overload
565+
def upper(self: LiteralString) -> LiteralString: ...
566+
@overload
489567
def upper(self) -> str: ... # type: ignore[misc]
568+
@overload
569+
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
570+
@overload
490571
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
491572
@staticmethod
492573
@overload
@@ -497,20 +578,36 @@ class str(Sequence[str]):
497578
@staticmethod
498579
@overload
499580
def maketrans(__x: str, __y: str, __z: str) -> dict[int, int | None]: ...
581+
@overload
582+
def __add__(self: LiteralString, __value: LiteralString) -> LiteralString: ...
583+
@overload
500584
def __add__(self, __value: str) -> str: ... # type: ignore[misc]
501585
# Incompatible with Sequence.__contains__
502586
def __contains__(self, __key: str) -> bool: ... # type: ignore[override]
503587
def __eq__(self, __value: object) -> bool: ...
504588
def __ge__(self, __value: str) -> bool: ...
505589
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
506590
def __gt__(self, __value: str) -> bool: ...
591+
def __hash__(self) -> int: ...
592+
@overload
593+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
594+
@overload
507595
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
508596
def __le__(self, __value: str) -> bool: ...
509597
def __len__(self) -> int: ...
510598
def __lt__(self, __value: str) -> bool: ...
599+
@overload
600+
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
601+
@overload
511602
def __mod__(self, __value: Any) -> str: ...
603+
@overload
604+
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
605+
@overload
512606
def __mul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
513607
def __ne__(self, __value: object) -> bool: ...
608+
@overload
609+
def __rmul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
610+
@overload
514611
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
515612
def __getnewargs__(self) -> tuple[str]: ...
516613

@@ -597,6 +694,7 @@ class bytes(Sequence[int]):
597694
def maketrans(__frm: ReadableBuffer, __to: ReadableBuffer) -> bytes: ...
598695
def __len__(self) -> int: ...
599696
def __iter__(self) -> Iterator[int]: ...
697+
def __hash__(self) -> int: ...
600698
@overload
601699
def __getitem__(self, __key: SupportsIndex) -> int: ...
602700
@overload
@@ -1004,7 +1102,13 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
10041102
__hash__: ClassVar[None] # type: ignore[assignment]
10051103
if sys.version_info >= (3, 9):
10061104
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
1105+
@overload
1106+
def __or__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
1107+
@overload
10071108
def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
1109+
@overload
1110+
def __ror__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
1111+
@overload
10081112
def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
10091113
# dict.__ior__ should be kept roughly in line with MutableMapping.update()
10101114
@overload # type: ignore[misc]
@@ -1665,11 +1769,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
16651769
# Instead, we special-case the most common examples of this: bool and literal integers.
16661770
if sys.version_info >= (3, 8):
16671771
@overload
1668-
def sum(__iterable: Iterable[bool], start: int = 0) -> int: ... # type: ignore[misc]
1772+
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = 0) -> int: ... # type: ignore[misc]
16691773

16701774
else:
16711775
@overload
1672-
def sum(__iterable: Iterable[bool], __start: int = 0) -> int: ... # type: ignore[misc]
1776+
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = 0) -> int: ... # type: ignore[misc]
16731777

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

mypy/typeshed/stdlib/collections/__init__.pyi

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
8383
@overload
8484
def fromkeys(cls, iterable: Iterable[_T], value: _S) -> UserDict[_T, _S]: ...
8585
if sys.version_info >= (3, 9):
86+
@overload
87+
def __or__(self, other: UserDict[_KT, _VT] | dict[_KT, _VT]) -> Self: ...
88+
@overload
8689
def __or__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ...
87-
def __ror__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc]
90+
@overload # type: ignore[misc]
91+
def __ror__(self, other: UserDict[_KT, _VT] | dict[_KT, _VT]) -> Self: ...
92+
@overload # type: ignore[misc]
93+
def __ror__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ...
8894
# UserDict.__ior__ should be kept roughly in line with MutableMapping.update()
8995
@overload # type: ignore[misc]
9096
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
@@ -391,6 +397,15 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
391397
def __missing__(self, __key: _KT) -> _VT: ...
392398
def __copy__(self) -> Self: ...
393399
def copy(self) -> Self: ...
400+
if sys.version_info >= (3, 9):
401+
@overload
402+
def __or__(self, __value: Mapping[_KT, _VT]) -> Self: ...
403+
@overload
404+
def __or__(self, __value: Mapping[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ...
405+
@overload
406+
def __ror__(self, __value: Mapping[_KT, _VT]) -> Self: ...
407+
@overload
408+
def __ror__(self, __value: Mapping[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ...
394409

395410
class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
396411
maps: list[MutableMapping[_KT, _VT]]
@@ -425,7 +440,13 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
425440
@overload
426441
def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> ChainMap[_T, _S]: ...
427442
if sys.version_info >= (3, 9):
443+
@overload
444+
def __or__(self, other: Mapping[_KT, _VT]) -> Self: ...
445+
@overload
428446
def __or__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ...
447+
@overload
448+
def __ror__(self, other: Mapping[_KT, _VT]) -> Self: ...
449+
@overload
429450
def __ror__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ...
430451
# ChainMap.__ior__ should be kept roughly in line with MutableMapping.update()
431452
@overload # type: ignore[misc]

mypy/typeshed/stdlib/datetime.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class timezone(tzinfo):
3535
def tzname(self, __dt: datetime | None) -> str: ...
3636
def utcoffset(self, __dt: datetime | None) -> timedelta: ...
3737
def dst(self, __dt: datetime | None) -> None: ...
38+
def __hash__(self) -> int: ...
3839

3940
if sys.version_info >= (3, 11):
4041
UTC: timezone
@@ -106,6 +107,7 @@ class date:
106107
@overload
107108
def __sub__(self, __value: date) -> timedelta: ...
108109

110+
def __hash__(self) -> int: ...
109111
def weekday(self) -> int: ...
110112
def isoweekday(self) -> int: ...
111113
if sys.version_info >= (3, 9):
@@ -143,6 +145,7 @@ class time:
143145
def __lt__(self, __value: time) -> bool: ...
144146
def __ge__(self, __value: time) -> bool: ...
145147
def __gt__(self, __value: time) -> bool: ...
148+
def __hash__(self) -> int: ...
146149
def isoformat(self, timespec: str = ...) -> str: ...
147150
@classmethod
148151
def fromisoformat(cls, __time_string: str) -> Self: ...
@@ -217,6 +220,7 @@ class timedelta:
217220
def __ge__(self, __value: timedelta) -> bool: ...
218221
def __gt__(self, __value: timedelta) -> bool: ...
219222
def __bool__(self) -> bool: ...
223+
def __hash__(self) -> int: ...
220224

221225
class datetime(date):
222226
min: ClassVar[datetime]

mypy/typeshed/stdlib/doctest.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Example:
8585
indent: int = 0,
8686
options: dict[int, bool] | None = None,
8787
) -> None: ...
88+
def __hash__(self) -> int: ...
8889
def __eq__(self, other: object) -> bool: ...
8990

9091
class DocTest:
@@ -103,6 +104,7 @@ class DocTest:
103104
lineno: int | None,
104105
docstring: str | None,
105106
) -> None: ...
107+
def __hash__(self) -> int: ...
106108
def __lt__(self, other: DocTest) -> bool: ...
107109
def __eq__(self, other: object) -> bool: ...
108110

@@ -210,6 +212,7 @@ class DocTestCase(unittest.TestCase):
210212
) -> None: ...
211213
def runTest(self) -> None: ...
212214
def format_failure(self, err: str) -> str: ...
215+
def __hash__(self) -> int: ...
213216
def __eq__(self, other: object) -> bool: ...
214217

215218
class SkipDocTestCase(DocTestCase):

0 commit comments

Comments
 (0)