From 5014f9f50ccbcc7121c29110bda8054c1f7121f8 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sun, 13 Feb 2022 14:24:27 +0300 Subject: [PATCH] Improve `__reduce__` signature accross `stdlib` (#7182) --- stdlib/decimal.pyi | 4 ++-- stdlib/multiprocessing/shared_memory.pyi | 4 ++-- stdlib/multiprocessing/sharedctypes.pyi | 2 +- stdlib/plistlib.pyi | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 89512dbbc..9b8678af3 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -145,7 +145,7 @@ class Decimal: def rotate(self, other: _Decimal, context: Context | None = ...) -> Decimal: ... def scaleb(self, other: _Decimal, context: Context | None = ...) -> Decimal: ... def shift(self, other: _Decimal, context: Context | None = ...) -> Decimal: ... - def __reduce__(self) -> tuple[type[Decimal], tuple[str]]: ... + def __reduce__(self: Self) -> tuple[type[Self], tuple[str]]: ... def __copy__(self: Self) -> Self: ... def __deepcopy__(self: Self, __memo: Any) -> Self: ... def __format__(self, __specifier: str, __context: Context | None = ...) -> str: ... @@ -183,7 +183,7 @@ class Context: # __setattr__() only allows to set a specific set of attributes, # already defined above. def __delattr__(self, __name: str) -> None: ... - def __reduce__(self) -> tuple[type[Context], tuple[Any, ...]]: ... + def __reduce__(self: Self) -> tuple[type[Self], tuple[Any, ...]]: ... def clear_flags(self) -> None: ... def clear_traps(self) -> None: ... def copy(self) -> Context: ... diff --git a/stdlib/multiprocessing/shared_memory.pyi b/stdlib/multiprocessing/shared_memory.pyi index 8255af382..56a5f7bc7 100644 --- a/stdlib/multiprocessing/shared_memory.pyi +++ b/stdlib/multiprocessing/shared_memory.pyi @@ -1,10 +1,10 @@ import sys +from _typeshed import Self from typing import Any, Generic, Iterable, TypeVar if sys.version_info >= (3, 9): from types import GenericAlias -_S = TypeVar("_S") _SLT = TypeVar("_SLT", int, float, bool, str, bytes, None) if sys.version_info >= (3, 8): @@ -24,7 +24,7 @@ if sys.version_info >= (3, 8): def __init__(self, sequence: Iterable[_SLT] | None = ..., *, name: str | None = ...) -> None: ... def __getitem__(self, position: int) -> _SLT: ... def __setitem__(self, position: int, value: _SLT) -> None: ... - def __reduce__(self: _S) -> tuple[_S, tuple[_SLT, ...]]: ... + def __reduce__(self: Self) -> tuple[Self, tuple[_SLT, ...]]: ... def __len__(self) -> int: ... @property def format(self) -> str: ... diff --git a/stdlib/multiprocessing/sharedctypes.pyi b/stdlib/multiprocessing/sharedctypes.pyi index bbe3c1739..440217a6e 100644 --- a/stdlib/multiprocessing/sharedctypes.pyi +++ b/stdlib/multiprocessing/sharedctypes.pyi @@ -76,7 +76,7 @@ class SynchronizedBase(Generic[_CT]): acquire: _AcquireFunc release: Callable[[], None] def __init__(self, obj: Any, lock: _LockLike | None = ..., ctx: Any | None = ...) -> None: ... - def __reduce__(self) -> tuple[Callable[..., Any], tuple[Any, _LockLike]]: ... + def __reduce__(self) -> tuple[Callable[[Any, _LockLike], SynchronizedBase[Any]], tuple[Any, _LockLike]]: ... def get_obj(self) -> _CT: ... def get_lock(self) -> _LockLike: ... def __enter__(self) -> bool: ... diff --git a/stdlib/plistlib.pyi b/stdlib/plistlib.pyi index 6f8157fe5..64c55afa0 100644 --- a/stdlib/plistlib.pyi +++ b/stdlib/plistlib.pyi @@ -1,4 +1,5 @@ import sys +from _typeshed import Self from datetime import datetime from enum import Enum from typing import IO, Any, Mapping, MutableMapping @@ -68,7 +69,7 @@ if sys.version_info >= (3, 8): data: int def __init__(self, data: int) -> None: ... def __index__(self) -> int: ... - def __reduce__(self) -> Any: ... + def __reduce__(self: Self) -> tuple[type[Self], tuple[int]]: ... def __hash__(self) -> int: ... class InvalidFileException(ValueError):