Skip to content

Commit

Permalink
Sync typeshed (#15792)
Browse files Browse the repository at this point in the history
Source commit:

python/typeshed@fe2ebd6

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
  • Loading branch information
3 people authored Aug 12, 2023
1 parent 7f22aaa commit 89c6596
Show file tree
Hide file tree
Showing 40 changed files with 326 additions and 100 deletions.
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.

@final
class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 10):
@property
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
Expand All @@ -81,6 +82,7 @@ class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented

@final
class dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocumented
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 10):
@property
def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ...
Expand Down
3 changes: 3 additions & 0 deletions mypy/typeshed/stdlib/_weakref.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ _T = TypeVar("_T")

@final
class CallableProxyType(Generic[_C]): # "weakcallableproxy"
def __eq__(self, __value: object) -> bool: ...
def __getattr__(self, attr: str) -> Any: ...
__call__: _C

@final
class ProxyType(Generic[_T]): # "weakproxy"
def __eq__(self, __value: object) -> bool: ...
def __getattr__(self, attr: str) -> Any: ...

class ReferenceType(Generic[_T]):
__callback__: Callable[[ReferenceType[_T]], Any]
def __new__(cls, __o: _T, __callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
def __call__(self) -> _T | None: ...
def __eq__(self, __value: object) -> bool: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def abstractmethod(funcobj: _FuncT) -> _FuncT: ...

class abstractclassmethod(classmethod[_T, _P, _R_co]):
__isabstractmethod__: Literal[True]
def __init__(self, callable: Callable[Concatenate[_T, _P], _R_co]) -> None: ...
def __init__(self, callable: Callable[Concatenate[type[_T], _P], _R_co]) -> None: ...

class abstractstaticmethod(staticmethod[_P, _R_co]):
__isabstractmethod__: Literal[True]
Expand Down
10 changes: 5 additions & 5 deletions mypy/typeshed/stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _ActionsContainer:
self,
*name_or_flags: str,
action: _ActionStr | type[Action] = ...,
nargs: int | _NArgsStr | _SUPPRESS_T = ...,
nargs: int | _NArgsStr | _SUPPRESS_T | None = None,
const: Any = ...,
default: Any = ...,
type: Callable[[str], _T] | FileType = ...,
Expand Down Expand Up @@ -171,7 +171,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
) -> None: ...

@overload
def parse_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> Namespace: ... # type: ignore[misc]
def parse_args(self, args: Sequence[str] | None = None, namespace: None = None) -> Namespace: ... # type: ignore[misc]
@overload
def parse_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
@overload
Expand Down Expand Up @@ -210,7 +210,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
def format_usage(self) -> str: ...
def format_help(self) -> str: ...
@overload
def parse_known_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> tuple[Namespace, list[str]]: ... # type: ignore[misc]
def parse_known_args(self, args: Sequence[str] | None = None, namespace: None = None) -> tuple[Namespace, list[str]]: ... # type: ignore[misc]
@overload
def parse_known_args(self, args: Sequence[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
@overload
Expand All @@ -219,13 +219,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
def exit(self, status: int = 0, message: str | None = None) -> NoReturn: ...
def error(self, message: str) -> NoReturn: ...
@overload
def parse_intermixed_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> Namespace: ... # type: ignore[misc]
def parse_intermixed_args(self, args: Sequence[str] | None = None, namespace: None = None) -> Namespace: ... # type: ignore[misc]
@overload
def parse_intermixed_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
@overload
def parse_intermixed_args(self, *, namespace: _N) -> _N: ...
@overload
def parse_known_intermixed_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> tuple[Namespace, list[str]]: ... # type: ignore[misc]
def parse_known_intermixed_args(self, args: Sequence[str] | None = None, namespace: None = None) -> tuple[Namespace, list[str]]: ... # type: ignore[misc]
@overload
def parse_known_intermixed_args(self, args: Sequence[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
@overload
Expand Down
6 changes: 6 additions & 0 deletions mypy/typeshed/stdlib/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ from collections.abc import Iterable
from typing import Any, Generic, MutableSequence, TypeVar, overload # noqa: Y022
from typing_extensions import Literal, Self, SupportsIndex, TypeAlias

if sys.version_info >= (3, 12):
from types import GenericAlias

_IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
_FloatTypeCode: TypeAlias = Literal["f", "d"]
_UnicodeTypeCode: TypeAlias = Literal["u"]
Expand Down Expand Up @@ -70,6 +73,7 @@ class array(MutableSequence[_T], Generic[_T]):
def __setitem__(self, __key: slice, __value: array[_T]) -> None: ...
def __delitem__(self, __key: SupportsIndex | slice) -> None: ...
def __add__(self, __value: array[_T]) -> array[_T]: ...
def __eq__(self, __value: object) -> bool: ...
def __ge__(self, __value: array[_T]) -> bool: ...
def __gt__(self, __value: array[_T]) -> bool: ...
def __iadd__(self, __value: array[_T]) -> Self: ... # type: ignore[override]
Expand All @@ -82,5 +86,7 @@ class array(MutableSequence[_T], Generic[_T]):
def __deepcopy__(self, __unused: Any) -> array[_T]: ...
def __buffer__(self, __flags: int) -> memoryview: ...
def __release_buffer__(self, __buffer: memoryview) -> None: ...
if sys.version_info >= (3, 12):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

ArrayType = array
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/asyncio/futures.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def isfuture(obj: object) -> TypeGuard[Future[Any]]: ...
class Future(Awaitable[_T], Iterable[_T]):
_state: str
@property
def _exception(self) -> BaseException: ...
def _exception(self) -> BaseException | None: ...
_blocking: bool
@property
def _log_traceback(self) -> bool: ...
Expand Down
34 changes: 28 additions & 6 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class staticmethod(Generic[_P, _R_co]):
@property
def __isabstractmethod__(self) -> bool: ...
def __init__(self, __f: Callable[_P, _R_co]) -> None: ...
@overload
def __get__(self, __instance: None, __owner: type) -> Callable[_P, _R_co]: ...
@overload
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[_P, _R_co]: ...
if sys.version_info >= (3, 10):
__name__: str
Expand All @@ -141,16 +144,19 @@ class staticmethod(Generic[_P, _R_co]):

class classmethod(Generic[_T, _P, _R_co]):
@property
def __func__(self) -> Callable[Concatenate[_T, _P], _R_co]: ...
def __func__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ...
@property
def __isabstractmethod__(self) -> bool: ...
def __init__(self, __f: Callable[Concatenate[_T, _P], _R_co]) -> None: ...
def __init__(self, __f: Callable[Concatenate[type[_T], _P], _R_co]) -> None: ...
@overload
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[_P, _R_co]: ...
@overload
def __get__(self, __instance: None, __owner: type[_T]) -> Callable[_P, _R_co]: ...
if sys.version_info >= (3, 10):
__name__: str
__qualname__: str
@property
def __wrapped__(self) -> Callable[Concatenate[_T, _P], _R_co]: ...
def __wrapped__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ...

class type:
@property
Expand Down Expand Up @@ -781,6 +787,8 @@ class memoryview(Sequence[int]):
def __contains__(self, __x: object) -> bool: ...
def __iter__(self) -> Iterator[int]: ...
def __len__(self) -> int: ...
def __eq__(self, __value: object) -> bool: ...
def __hash__(self) -> int: ...
@overload
def __setitem__(self, __key: slice, __value: ReadableBuffer) -> None: ...
@overload
Expand Down Expand Up @@ -848,6 +856,7 @@ class slice:
def __init__(self, __stop: Any) -> None: ...
@overload
def __init__(self, __start: Any, __stop: Any, __step: Any = ...) -> None: ...
def __eq__(self, __value: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...

Expand All @@ -864,6 +873,8 @@ class tuple(Sequence[_T_co], Generic[_T_co]):
def __le__(self, __value: tuple[_T_co, ...]) -> bool: ...
def __gt__(self, __value: tuple[_T_co, ...]) -> bool: ...
def __ge__(self, __value: tuple[_T_co, ...]) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
def __hash__(self) -> int: ...
@overload
def __add__(self, __value: tuple[_T_co, ...]) -> tuple[_T_co, ...]: ...
@overload
Expand Down Expand Up @@ -952,6 +963,7 @@ class list(MutableSequence[_T], Generic[_T]):
def __ge__(self, __value: list[_T]) -> bool: ...
def __lt__(self, __value: list[_T]) -> bool: ...
def __le__(self, __value: list[_T]) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...

Expand Down Expand Up @@ -991,19 +1003,24 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> dict[_T, _S]: ...
# Positional-only in dict, but not in MutableMapping
@overload
@overload # type: ignore[override]
def get(self, __key: _KT) -> _VT | None: ...
@overload
def get(self, __key: _KT, __default: _VT | _T) -> _VT | _T: ...
def get(self, __key: _KT, __default: _VT) -> _VT: ...
@overload
def get(self, __key: _KT, __default: _T) -> _VT | _T: ...
@overload
def pop(self, __key: _KT) -> _VT: ...
@overload
def pop(self, __key: _KT, __default: _VT | _T) -> _VT | _T: ...
def pop(self, __key: _KT, __default: _VT) -> _VT: ...
@overload
def pop(self, __key: _KT, __default: _T) -> _VT | _T: ...
def __len__(self) -> int: ...
def __getitem__(self, __key: _KT) -> _VT: ...
def __setitem__(self, __key: _KT, __value: _VT) -> None: ...
def __delitem__(self, __key: _KT) -> None: ...
def __iter__(self) -> Iterator[_KT]: ...
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 8):
def __reversed__(self) -> Iterator[_KT]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
Expand Down Expand Up @@ -1058,6 +1075,7 @@ class set(MutableSet[_T], Generic[_T]):
def __lt__(self, __value: AbstractSet[object]) -> bool: ...
def __ge__(self, __value: AbstractSet[object]) -> bool: ...
def __gt__(self, __value: AbstractSet[object]) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
Expand Down Expand Up @@ -1086,6 +1104,8 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
def __lt__(self, __value: AbstractSet[object]) -> bool: ...
def __ge__(self, __value: AbstractSet[object]) -> bool: ...
def __gt__(self, __value: AbstractSet[object]) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...

Expand All @@ -1111,6 +1131,8 @@ class range(Sequence[int]):
def count(self, __value: int) -> int: ...
def index(self, __value: int) -> int: ... # type: ignore[override]
def __len__(self) -> int: ...
def __eq__(self, __value: object) -> bool: ...
def __hash__(self) -> int: ...
def __contains__(self, __key: object) -> bool: ...
def __iter__(self) -> Iterator[int]: ...
@overload
Expand Down
7 changes: 6 additions & 1 deletion mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class UserString(Sequence[UserString]):
def __gt__(self, string: str | UserString) -> bool: ...
def __ge__(self, string: str | UserString) -> bool: ...
def __eq__(self, string: object) -> bool: ...
def __hash__(self) -> int: ...
def __contains__(self, char: object) -> bool: ...
def __len__(self) -> int: ...
def __getitem__(self, index: SupportsIndex | slice) -> Self: ...
Expand Down Expand Up @@ -257,6 +258,7 @@ class deque(MutableSequence[_T], Generic[_T]):
def __le__(self, __value: deque[_T]) -> bool: ...
def __gt__(self, __value: deque[_T]) -> bool: ...
def __ge__(self, __value: deque[_T]) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...

Expand Down Expand Up @@ -365,6 +367,7 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
def setdefault(self: OrderedDict[_KT, _T | None], key: _KT, default: None = None) -> _T | None: ...
@overload
def setdefault(self, key: _KT, default: _VT) -> _VT: ...
def __eq__(self, __value: object) -> bool: ...

class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
default_factory: Callable[[], _VT] | None
Expand Down Expand Up @@ -429,7 +432,9 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def pop(self, key: _KT) -> _VT: ...
@overload
def pop(self, key: _KT, default: _VT | _T) -> _VT | _T: ...
def pop(self, key: _KT, default: _VT) -> _VT: ...
@overload
def pop(self, key: _KT, default: _T) -> _VT | _T: ...
def copy(self) -> Self: ...
__copy__ = copy
# All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime, so the signature should be kept in line with `dict.fromkeys`.
Expand Down
14 changes: 11 additions & 3 deletions mypy/typeshed/stdlib/contextvars.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ class ContextVar(Generic[_T]):
def __init__(self, name: str) -> None: ...
@overload
def __init__(self, name: str, *, default: _T) -> None: ...
def __hash__(self) -> int: ...
@property
def name(self) -> str: ...
@overload
def get(self) -> _T: ...
if sys.version_info >= (3, 8):
@overload
def get(self, default: _D | _T) -> _D | _T: ...
def get(self, default: _T) -> _T: ...
@overload
def get(self, default: _D) -> _D | _T: ...
else:
@overload
def get(self, __default: _D | _T) -> _D | _T: ...
def get(self, __default: _T) -> _T: ...
@overload
def get(self, __default: _D) -> _D | _T: ...

def set(self, __value: _T) -> Token[_T]: ...
def reset(self, __token: Token[_T]) -> None: ...
Expand All @@ -52,11 +57,14 @@ def copy_context() -> Context: ...
class Context(Mapping[ContextVar[Any], Any]):
def __init__(self) -> None: ...
@overload
def get(self, __key: ContextVar[_T]) -> _T | None: ...
def get(self, __key: ContextVar[_T], __default: None = None) -> _T | None: ... # type: ignore[misc] # overlapping overloads
@overload
def get(self, __key: ContextVar[_T], __default: _T) -> _T: ...
@overload
def get(self, __key: ContextVar[_T], __default: _D) -> _T | _D: ...
def run(self, callable: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
def copy(self) -> Context: ...
def __getitem__(self, __key: ContextVar[_T]) -> _T: ...
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
def __len__(self) -> int: ...
def __eq__(self, __value: object) -> bool: ...
6 changes: 6 additions & 0 deletions mypy/typeshed/stdlib/datetime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class timezone(tzinfo):
def utcoffset(self, __dt: datetime | None) -> timedelta: ...
def dst(self, __dt: datetime | None) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, __value: object) -> bool: ...

if sys.version_info >= (3, 11):
UTC: timezone
Expand Down Expand Up @@ -87,6 +88,7 @@ class date:
def __lt__(self, __value: date) -> bool: ...
def __ge__(self, __value: date) -> bool: ...
def __gt__(self, __value: date) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 8):
def __add__(self, __value: timedelta) -> Self: ...
def __radd__(self, __value: timedelta) -> Self: ...
Expand Down Expand Up @@ -145,6 +147,7 @@ class time:
def __lt__(self, __value: time) -> bool: ...
def __ge__(self, __value: time) -> bool: ...
def __gt__(self, __value: time) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
def __hash__(self) -> int: ...
def isoformat(self, timespec: str = ...) -> str: ...
@classmethod
Expand Down Expand Up @@ -219,6 +222,7 @@ class timedelta:
def __lt__(self, __value: timedelta) -> bool: ...
def __ge__(self, __value: timedelta) -> bool: ...
def __gt__(self, __value: timedelta) -> bool: ...
def __eq__(self, __value: object) -> bool: ...
def __bool__(self) -> bool: ...
def __hash__(self) -> int: ...

Expand Down Expand Up @@ -310,6 +314,8 @@ class datetime(date):
def __lt__(self, __value: datetime) -> bool: ... # type: ignore[override]
def __ge__(self, __value: datetime) -> bool: ... # type: ignore[override]
def __gt__(self, __value: datetime) -> bool: ... # type: ignore[override]
def __eq__(self, __value: object) -> bool: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 8):
@overload # type: ignore[override]
def __sub__(self, __value: timedelta) -> Self: ...
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/email/charset.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class Charset:
def get_body_encoding(self) -> str | Callable[[Message], None]: ...
def get_output_charset(self) -> str | None: ...
def header_encode(self, string: str) -> str: ...
def header_encode_lines(self, string: str, maxlengths: Iterator[int]) -> list[str]: ...
def header_encode_lines(self, string: str, maxlengths: Iterator[int]) -> list[str | None]: ...
@overload
def body_encode(self, string: None) -> None: ...
@overload
def body_encode(self, string: str) -> str: ...
def body_encode(self, string: str | bytes) -> str: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, __value: object) -> bool: ...

Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/email/policy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ compat32: Compat32
class EmailPolicy(Policy):
utf8: bool
refold_source: str
header_factory: Callable[[str, str], str]
header_factory: Callable[[str, Any], Any]
content_manager: ContentManager
def __init__(
self,
Expand All @@ -70,9 +70,9 @@ class EmailPolicy(Policy):
content_manager: ContentManager = ...,
) -> None: ...
def header_source_parse(self, sourcelines: list[str]) -> tuple[str, str]: ...
def header_store_parse(self, name: str, value: str) -> tuple[str, str]: ...
def header_fetch_parse(self, name: str, value: str) -> str: ...
def fold(self, name: str, value: str) -> str: ...
def header_store_parse(self, name: str, value: Any) -> tuple[str, Any]: ...
def header_fetch_parse(self, name: str, value: str) -> Any: ...
def fold(self, name: str, value: str) -> Any: ...
def fold_binary(self, name: str, value: str) -> bytes: ...

default: EmailPolicy
Expand Down
Loading

0 comments on commit 89c6596

Please sign in to comment.