Skip to content

Commit c44fe1a

Browse files
AlexWaygoodsvalentin
authored andcommitted
Sync typeshed
Source commit: python/typeshed@fc7d472
1 parent 59ba429 commit c44fe1a

File tree

19 files changed

+290
-97
lines changed

19 files changed

+290
-97
lines changed

mypy/typeshed/stdlib/_collections_abc.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from abc import abstractmethod
33
from types import MappingProxyType
4-
from typing import ( # noqa: Y022,Y038
4+
from typing import ( # noqa: Y022,Y038,Y057
55
AbstractSet as Set,
66
AsyncGenerator as AsyncGenerator,
77
AsyncIterable as AsyncIterable,

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/asyncio/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ _T = TypeVar("_T")
3636

3737
# Aliases imported by multiple submodules in typeshed
3838
if sys.version_info >= (3, 12):
39-
_AwaitableLike: TypeAlias = Awaitable[_T]
40-
_CoroutineLike: TypeAlias = Coroutine[Any, Any, _T]
39+
_AwaitableLike: TypeAlias = Awaitable[_T] # noqa: Y047
40+
_CoroutineLike: TypeAlias = Coroutine[Any, Any, _T] # noqa: Y047
4141
else:
4242
_AwaitableLike: TypeAlias = Generator[Any, None, _T] | Awaitable[_T]
4343
_CoroutineLike: TypeAlias = Generator[Any, None, _T] | Coroutine[Any, Any, _T]

mypy/typeshed/stdlib/asyncio/base_events.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class BaseEventLoop(AbstractEventLoop):
263263
server_hostname: str | None = None,
264264
ssl_handshake_timeout: float | None = None,
265265
ssl_shutdown_timeout: float | None = None,
266-
) -> Transport: ...
266+
) -> Transport | None: ...
267267
async def connect_accepted_socket(
268268
self,
269269
protocol_factory: Callable[[], _ProtocolT],
@@ -317,7 +317,7 @@ class BaseEventLoop(AbstractEventLoop):
317317
server_side: bool = False,
318318
server_hostname: str | None = None,
319319
ssl_handshake_timeout: float | None = None,
320-
) -> Transport: ...
320+
) -> Transport | None: ...
321321
async def connect_accepted_socket(
322322
self,
323323
protocol_factory: Callable[[], _ProtocolT],

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class AbstractEventLoop:
358358
server_hostname: str | None = None,
359359
ssl_handshake_timeout: float | None = None,
360360
ssl_shutdown_timeout: float | None = None,
361-
) -> Transport: ...
361+
) -> Transport | None: ...
362362
async def create_unix_server(
363363
self,
364364
protocol_factory: _ProtocolFactory,
@@ -418,7 +418,7 @@ class AbstractEventLoop:
418418
server_side: bool = False,
419419
server_hostname: str | None = None,
420420
ssl_handshake_timeout: float | None = None,
421-
) -> Transport: ...
421+
) -> Transport | None: ...
422422
async def create_unix_server(
423423
self,
424424
protocol_factory: _ProtocolFactory,

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ from typing import ( # noqa: Y022
5353
overload,
5454
type_check_only,
5555
)
56-
from typing_extensions import ( # type: ignore
56+
from typing_extensions import (
5757
Concatenate,
5858
Literal,
59+
LiteralString,
5960
ParamSpec,
6061
Self,
6162
SupportsIndex,
@@ -432,21 +433,39 @@ class str(Sequence[str]):
432433
def __new__(cls, object: object = ...) -> Self: ...
433434
@overload
434435
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
436+
@overload
437+
def capitalize(self: LiteralString) -> LiteralString: ...
438+
@overload
435439
def capitalize(self) -> str: ... # type: ignore[misc]
440+
@overload
441+
def casefold(self: LiteralString) -> LiteralString: ...
442+
@overload
436443
def casefold(self) -> str: ... # type: ignore[misc]
444+
@overload
445+
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
446+
@overload
437447
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
438448
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
439449
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
440450
def endswith(
441451
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
442452
) -> bool: ...
443453
if sys.version_info >= (3, 8):
454+
@overload
455+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
456+
@overload
444457
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
445458
else:
459+
@overload
460+
def expandtabs(self: LiteralString, tabsize: int = 8) -> LiteralString: ...
461+
@overload
446462
def expandtabs(self, tabsize: int = 8) -> str: ... # type: ignore[misc]
447463

448464
def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
449-
def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore
465+
@overload
466+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
467+
@overload
468+
def format(self, *args: object, **kwargs: object) -> str: ...
450469
def format_map(self, map: _FormatMapMapping) -> str: ...
451470
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
452471
def isalnum(self) -> bool: ...
@@ -461,32 +480,91 @@ class str(Sequence[str]):
461480
def isspace(self) -> bool: ...
462481
def istitle(self) -> bool: ...
463482
def isupper(self) -> bool: ...
483+
@overload
484+
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
485+
@overload
464486
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
487+
@overload
488+
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
489+
@overload
465490
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
491+
@overload
492+
def lower(self: LiteralString) -> LiteralString: ...
493+
@overload
466494
def lower(self) -> str: ... # type: ignore[misc]
495+
@overload
496+
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
497+
@overload
467498
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
499+
@overload
500+
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
501+
@overload
468502
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
503+
@overload
504+
def replace(
505+
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
506+
) -> LiteralString: ...
507+
@overload
469508
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
470509
if sys.version_info >= (3, 9):
510+
@overload
511+
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
512+
@overload
471513
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
514+
@overload
515+
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
516+
@overload
472517
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]
473518

474519
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
475520
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
521+
@overload
522+
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
523+
@overload
476524
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
525+
@overload
526+
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
527+
@overload
477528
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
529+
@overload
530+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
531+
@overload
478532
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
533+
@overload
534+
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
535+
@overload
479536
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
537+
@overload
538+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
539+
@overload
480540
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
541+
@overload
542+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
543+
@overload
481544
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
482545
def startswith(
483546
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
484547
) -> bool: ...
548+
@overload
549+
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
550+
@overload
485551
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
552+
@overload
553+
def swapcase(self: LiteralString) -> LiteralString: ...
554+
@overload
486555
def swapcase(self) -> str: ... # type: ignore[misc]
556+
@overload
557+
def title(self: LiteralString) -> LiteralString: ...
558+
@overload
487559
def title(self) -> str: ... # type: ignore[misc]
488560
def translate(self, __table: _TranslateTable) -> str: ...
561+
@overload
562+
def upper(self: LiteralString) -> LiteralString: ...
563+
@overload
489564
def upper(self) -> str: ... # type: ignore[misc]
565+
@overload
566+
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
567+
@overload
490568
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
491569
@staticmethod
492570
@overload
@@ -497,20 +575,35 @@ class str(Sequence[str]):
497575
@staticmethod
498576
@overload
499577
def maketrans(__x: str, __y: str, __z: str) -> dict[int, int | None]: ...
578+
@overload
579+
def __add__(self: LiteralString, __value: LiteralString) -> LiteralString: ...
580+
@overload
500581
def __add__(self, __value: str) -> str: ... # type: ignore[misc]
501582
# Incompatible with Sequence.__contains__
502583
def __contains__(self, __key: str) -> bool: ... # type: ignore[override]
503584
def __eq__(self, __value: object) -> bool: ...
504585
def __ge__(self, __value: str) -> bool: ...
505586
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
506587
def __gt__(self, __value: str) -> bool: ...
588+
@overload
589+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
590+
@overload
507591
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
508592
def __le__(self, __value: str) -> bool: ...
509593
def __len__(self) -> int: ...
510594
def __lt__(self, __value: str) -> bool: ...
511-
def __mod__(self, __value: Any) -> str: ... # type: ignore
595+
@overload
596+
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
597+
@overload
598+
def __mod__(self, __value: Any) -> str: ...
599+
@overload
600+
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
601+
@overload
512602
def __mul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
513603
def __ne__(self, __value: object) -> bool: ...
604+
@overload
605+
def __rmul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
606+
@overload
514607
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
515608
def __getnewargs__(self) -> tuple[str]: ...
516609

@@ -1665,11 +1758,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
16651758
# Instead, we special-case the most common examples of this: bool and literal integers.
16661759
if sys.version_info >= (3, 8):
16671760
@overload
1668-
def sum(__iterable: Iterable[bool], start: int = 0) -> int: ... # type: ignore[misc]
1761+
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = 0) -> int: ... # type: ignore[misc]
16691762

16701763
else:
16711764
@overload
1672-
def sum(__iterable: Iterable[bool], __start: int = 0) -> int: ... # type: ignore[misc]
1765+
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = 0) -> int: ... # type: ignore[misc]
16731766

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

mypy/typeshed/stdlib/codecs.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class _IncrementalDecoder(Protocol):
9696
def __call__(self, errors: str = ...) -> IncrementalDecoder: ...
9797

9898
class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
99+
_is_text_encoding: bool
99100
@property
100101
def encode(self) -> _Encoder: ...
101102
@property

mypy/typeshed/stdlib/collections/__init__.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from _collections_abc import dict_items, dict_keys, dict_values
3-
from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
3+
from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
44
from typing import Any, Generic, NoReturn, TypeVar, overload
55
from typing_extensions import Self, SupportsIndex, final
66

@@ -299,10 +299,10 @@ class Counter(dict[_T, int], Generic[_T]):
299299
def __pos__(self) -> Counter[_T]: ...
300300
def __neg__(self) -> Counter[_T]: ...
301301
# several type: ignores because __iadd__ is supposedly incompatible with __add__, etc.
302-
def __iadd__(self, other: Counter[_T]) -> Self: ... # type: ignore[misc]
303-
def __isub__(self, other: Counter[_T]) -> Self: ...
304-
def __iand__(self, other: Counter[_T]) -> Self: ...
305-
def __ior__(self, other: Counter[_T]) -> Self: ... # type: ignore[override,misc]
302+
def __iadd__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[misc]
303+
def __isub__(self, other: SupportsItems[_T, int]) -> Self: ...
304+
def __iand__(self, other: SupportsItems[_T, int]) -> Self: ...
305+
def __ior__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[override,misc]
306306
if sys.version_info >= (3, 10):
307307
def total(self) -> int: ...
308308
def __le__(self, other: Counter[Any]) -> bool: ...

mypy/typeshed/stdlib/email/utils.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import sys
3+
from _typeshed import Unused
34
from email import _ParamType
45
from email.charset import Charset
56
from typing import overload
@@ -51,7 +52,13 @@ else:
5152
def mktime_tz(data: _PDTZ) -> int: ...
5253
def formatdate(timeval: float | None = None, localtime: bool = False, usegmt: bool = False) -> str: ...
5354
def format_datetime(dt: datetime.datetime, usegmt: bool = False) -> str: ...
54-
def localtime(dt: datetime.datetime | None = None, isdst: int = -1) -> datetime.datetime: ...
55+
56+
if sys.version_info >= (3, 12):
57+
def localtime(dt: datetime.datetime | None = None, isdst: Unused = None) -> datetime.datetime: ...
58+
59+
else:
60+
def localtime(dt: datetime.datetime | None = None, isdst: int = -1) -> datetime.datetime: ...
61+
5562
def make_msgid(idstring: str | None = None, domain: str | None = None) -> str: ...
5663
def decode_rfc2231(s: str) -> tuple[str | None, str | None, str]: ...
5764
def encode_rfc2231(s: str, charset: str | None = None, language: str | None = None) -> str: ...

mypy/typeshed/stdlib/enum.pyi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import types
44
from _typeshed import SupportsKeysAndGetItem, Unused
55
from abc import ABCMeta
66
from builtins import property as _builtins_property
7-
from collections.abc import Iterable, Iterator, Mapping
7+
from collections.abc import Callable, Iterable, Iterator, Mapping
88
from typing import Any, Generic, TypeVar, overload
99
from typing_extensions import Literal, Self, TypeAlias
1010

@@ -34,6 +34,9 @@ if sys.version_info >= (3, 11):
3434
"verify",
3535
]
3636

37+
if sys.version_info >= (3, 12):
38+
__all__ += ["pickle_by_enum_name", "pickle_by_global_name"]
39+
3740
_EnumMemberT = TypeVar("_EnumMemberT")
3841
_EnumerationT = TypeVar("_EnumerationT", bound=type[Enum])
3942

@@ -234,6 +237,8 @@ if sys.version_info >= (3, 11):
234237
_value_: str
235238
@_magic_enum_attr
236239
def value(self) -> str: ...
240+
@staticmethod
241+
def _generate_next_value_(name: str, start: int, count: int, last_values: list[str]) -> str: ...
237242

238243
class EnumCheck(StrEnum):
239244
CONTINUOUS: str
@@ -289,3 +294,7 @@ class auto(IntFlag):
289294
@_magic_enum_attr
290295
def value(self) -> Any: ...
291296
def __new__(cls) -> Self: ...
297+
298+
if sys.version_info >= (3, 12):
299+
def pickle_by_global_name(self: Enum, proto: int) -> str: ...
300+
def pickle_by_enum_name(self: _EnumMemberT, proto: int) -> tuple[Callable[..., Any], tuple[type[_EnumMemberT], str]]: ...

0 commit comments

Comments
 (0)