10000 Sync typeshed by AlexWaygood · Pull Request #15590 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Sync typeshed #15590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Sync typeshed
  • Loading branch information
AlexWaygood committed Jul 4, 2023
commit c41510548e644508966d7519d42d783bab5b2610
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from abc import abstractmethod
from types import MappingProxyType
from typing import ( # noqa: Y022,Y038
from typing import ( # noqa: Y022,Y038,Y057
AbstractSet as Set,
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
Expand Down
6 changes: 5 additions & 1 deletion mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ class Array(Generic[_CT], _CData):
def _type_(self) -> type[_CT]: ...
@_type_.setter
def _type_(self, value: type[_CT]) -> None: ...
raw: bytes # Note: only available if _CT == c_char
# Note: only available if _CT == c_char
@property
def raw(self) -> bytes: ...
@raw.setter
def raw(self, value: ReadableBuffer) -> None: ...
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ _T = TypeVar("_T")

# Aliases imported by multiple submodules in typeshed
if sys.version_info >= (3, 12):
_AwaitableLike: TypeAlias = Awaitable[_T]
_CoroutineLike: TypeAlias = Coroutine[Any, Any, _T]
_AwaitableLike: TypeAlias = Awaitable[_T] # noqa: Y047
_CoroutineLike: TypeAlias = Coroutine[Any, Any, _T] # noqa: Y047
else:
_AwaitableLike: TypeAlias = Generator[Any, None, _T] | Awaitable[_T]
_CoroutineLike: TypeAlias = Generator[Any, None, _T] | Coroutine[Any, Any, _T]
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class BaseEventLoop(AbstractEventLoop):
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
ssl_shutdown_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def connect_accepted_socket(
self,
protocol_factory: Callable[[], _ProtocolT],
Expand Down Expand Up @@ -317,7 +317,7 @@ class BaseEventLoop(AbstractEventLoop):
server_side: bool = False,
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def connect_accepted_socket(
self,
protocol_factory: Callable[[], _ProtocolT],
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class AbstractEventLoop:
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
ssl_shutdown_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
Expand Down Expand Up @@ -418,7 +418,7 @@ class AbstractEventLoop:
server_side: bool = False,
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
Expand Down
103 changes: 98 additions & 5 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ from typing import ( # noqa: Y022
overload,
type_check_only,
)
from typing_extensions import ( # type: ignore
from typing_extensions import (
Concatenate,
Literal,
LiteralString,
ParamSpec,
Self,
SupportsIndex,
Expand Down Expand Up @@ -432,21 +433,39 @@ class str(Sequence[str]):
def __new__(cls, object: object = ...) -> Self: ...
@overload
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
@overload
def capitalize(self: LiteralString) -> LiteralString: ...
@overload
def capitalize(self) -> str: ... # type: ignore[misc]
@overload
def casefold(self: LiteralString) -> LiteralString: ...
@overload
def casefold(self) -> str: ... # type: ignore[misc]
@overload
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
@overload
def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
def endswith(
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
if sys.version_info >= (3, 8):
@overload
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
@overload
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
else:
@overload
def expandtabs(self: LiteralString, tabsize: int = 8) -> LiteralString: ...
@overload
def expandtabs(self, tabsize: int = 8) -> str: ... # type: ignore[misc]

def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore
@overload
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
@overload
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, map: _FormatMapMapping) -> str: ...
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def isalnum(self) -> bool: ...
Expand All @@ -461,32 +480,91 @@ class str(Sequence[str]):
def isspace(self) -> bool: ...
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
@overload
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
@overload
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
@overload
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
@overload
def ljust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
@overload
def lower(self: LiteralString) -> LiteralString: ...
@overload
def lower(self) -> str: ... # type: ignore[misc]
@overload
def lstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
@overload
def lstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
@overload
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
@overload
def replace(
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = -1
) -> LiteralString: ...
@overload
def replace(self, __old: str, __new: str, __count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 9):
@overload
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
@overload
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
@overload
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
@overload
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]

def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@overload
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = " ") -> LiteralString: ...
@overload
def rjust(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc]
@overload
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
@overload
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
@overload
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
@overload
def rstrip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
@overload
def rstrip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
@overload
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
@overload
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
@overload
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
@overload
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
def startswith(
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
@overload
def strip(self: LiteralString, __chars: LiteralString | None = None) -> LiteralString: ...
@overload
def strip(self, __chars: str | None = None) -> str: ... # type: ignore[misc]
@overload
def swapcase(self: LiteralString) -> LiteralString: ...
@overload
def swapcase(self) -> str: ... # type: ignore[misc]
@overload
def title(self: LiteralString) -> LiteralString: ...
@overload
def title(self) -> str: ... # type: ignore[misc]
def translate(self, __table: _TranslateTable) -> str: ...
@overload
def upper(self: LiteralString) -> LiteralString: ...
@overload
def upper(self) -> str: ... # type: ignore[misc]
@overload
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
@overload
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
@staticmethod
@overload
Expand All @@ -497,20 +575,35 @@ class str(Sequence[str]):
@staticmethod
@overload
def maketrans(__x: str, __y: str, __z: str) -> dict[int, int | None]: ...
@overload
def __add__(self: LiteralString, __value: LiteralString) -> LiteralString: ...
@overload
def __add__(self, __value: str) -> str: ... # type: ignore[misc]
# Incompatible with Sequence.__contains__
def __contains__(self, __key: str) -> bool: ... # type: ignore[override]
def __eq__(self, __value: object) -> bool: ...
def __ge__(self, __value: str) -> bool: ...
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
def __gt__(self, __value: str) -> bool: ...
@overload
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
@overload
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
def __le__(self, __value: str) -> bool: ...
def __len__(self) -> int: ...
def __lt__(self, __value: str) -> bool: ...
def __mod__(self, __value: Any) -> str: ... # type: ignore
@overload
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
@overload
def __mod__(self, __value: Any) -> str: ...
@overload
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
@overload
def __mul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
def __ne__(self, __value: object) -> bool: ...
@overload
def __rmul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
@overload
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
def __getnewargs__(self) -> tuple[str]: ...

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

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

@overload
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class _IncrementalDecoder(Protocol):
def __call__(self, errors: str = ...) -> IncrementalDecoder: ...

class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
_is_text_encoding: bool
@property
def encode(self) -> _Encoder: ...
@property
Expand Down
10 changes: 5 additions & 5 deletions mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from typing import Any, Generic, NoReturn, TypeVar, overload
from typing_extensions import Self, SupportsIndex, final

Expand Down Expand Up @@ -299,10 +299,10 @@ class Counter(dict[_T, int], Generic[_T]):
def __pos__(self) -> Counter[_T]: ...
def __neg__(self) -> Counter[_T]: ...
# several type: ignores because __iadd__ is supposedly incompatible with __add__, etc.
def __iadd__(self, other: Counter[_T]) -> Self: ... # type: ignore[misc]
def __isub__(self, other: Counter[_T]) -> Self: ...
def __iand__(self, other: Counter[_T]) -> Self: ...
def __ior__(self, other: Counter[_T]) -> Self: ... # type: ignore[override,misc]
def __iadd__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[misc]
def __isub__(self, other: SupportsItems[_T, int]) -> Self: ...
def __iand__(self, other: SupportsItems[_T, int]) -> Self: ...
def __ior__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[override,misc]
if sys.version_info >= (3, 10):
def total(self) -> int: ...
def __le__(self, other: Counter[Any]) -> bool: ...
Expand Down
9 changes: 8 additions & 1 deletion mypy/typeshed/stdlib/email/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import sys
from _typeshed import Unused
from email import _ParamType
from email.charset import Charset
from typing import overload
Expand Down Expand Up @@ -51,7 +52,13 @@ else:
def mktime_tz(data: _PDTZ) -> int: ...
def formatdate(timeval: float | None = None, localtime: bool = False, usegmt: bool = False) -> str: ...
def format_datetime(dt: datetime.datetime, usegmt: bool = False) -> str: ...
def localtime(dt: datetime.datetime | None = None, isdst: int = -1) -> datetime.datetime: ...

if sys.version_info >= (3, 12):
def localtime(dt: datetime.datetime | None = None, isdst: Unused = None) -> datetime.datetime: ...

else:
def localtime(dt: datetime.datetime | None = None, isdst: int = -1) -> datetime.datetime: ...

def make_msgid(idstring: str | None = None, domain: str | None = None) -> str: ...
def decode_rfc2231(s: str) -> tuple[str | None, str | None, str]: ...
def encode_rfc2231(s: str, charset: str | None = None, language: str | None = None) -> str: ...
Expand Down
11 changes: 10 additions & 1 deletion mypy/typeshed/stdlib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import types
from _typeshed import SupportsKeysAndGetItem, Unused
from abc import ABCMeta
from builtins import property as _builtins_property
from collections.abc import Iterable, Iterator, Mapping
from collections.abc import Callable, Iterable, Iterator, Mapping
from typing import Any, Generic, TypeVar, overload
from typing_extensions import Literal, Self, TypeAlias

Expand Down Expand Up @@ -34,6 +34,9 @@ if sys.version_info >= (3, 11):
"verify",
]

if sys.version_info >= (3, 12):
__all__ += ["pickle_by_enum_name", "pickle_by_global_name"]

_EnumMemberT = TypeVar("_EnumMemberT")
_EnumerationT = TypeVar("_EnumerationT", bound=type[Enum])

Expand Down Expand Up @@ -234,6 +237,8 @@ if sys.version_info >= (3, 11):
_value_: str
@_magic_enum_attr
def value(self) -> str: ...
@staticmethod
def _generate_next_value_(name: str, start: int, count: int, last_values: list[str]) -> str: ...

class EnumCheck(StrEnum):
CONTINUOUS: str
Expand Down Expand Up @@ -289,3 +294,7 @@ class auto(IntFlag):
@_magic_enum_attr
def value(self) -> Any: ...
def __new__(cls) -> Self: ...

if sys.version_info >= (3, 12):
def pickle_by_global_name(self: Enum, proto: int) -> str: ...
def pickle_by_enum_name(self: _EnumMemberT, proto: int) -> tuple[Callable[..., Any], tuple[type[_EnumMemberT], str]]: ...
Loading
0