mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-30 16:14:24 +08:00
stdlib: Add several missing __(deep)copy__ methods (#7242)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from typing import BinaryIO, Generic, Iterable, MutableSequence, TypeVar, Union, overload
|
||||
from typing import Any, BinaryIO, Generic, Iterable, MutableSequence, TypeVar, Union, overload
|
||||
from typing_extensions import Literal, SupportsIndex
|
||||
|
||||
_IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
|
||||
@@ -68,5 +68,7 @@ class array(MutableSequence[_T], Generic[_T]):
|
||||
def __lt__(self, __other: array[_T]) -> bool: ...
|
||||
def __mul__(self, __n: int) -> array[_T]: ...
|
||||
def __rmul__(self, __n: int) -> array[_T]: ...
|
||||
def __copy__(self) -> array[_T]: ...
|
||||
def __deepcopy__(self, __unused: Any) -> array[_T]: ...
|
||||
|
||||
ArrayType = array
|
||||
|
||||
@@ -57,6 +57,9 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def __iter__(self) -> Iterator[_KT]: ...
|
||||
def __contains__(self, key: object) -> bool: ...
|
||||
def copy(self: Self) -> Self: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
def __copy__(self: Self) -> Self: ...
|
||||
|
||||
# `UserDict.fromkeys` has the same semantics as `dict.fromkeys`, so should be kept in line with `dict.fromkeys`.
|
||||
# TODO: Much like `dict.fromkeys`, the true signature of `UserDict.fromkeys` is inexpressible in the current type system.
|
||||
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
|
||||
@@ -105,6 +108,9 @@ class UserList(MutableSequence[_T]):
|
||||
def pop(self, i: int = ...) -> _T: ...
|
||||
def remove(self, item: _T) -> None: ...
|
||||
def copy(self: Self) -> Self: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
def __copy__(self: Self) -> Self: ...
|
||||
|
||||
def count(self, item: _T) -> int: ...
|
||||
# All arguments are passed to `list.index` at runtime, so the signature should be kept in line with `list.index`.
|
||||
def index(self, item: _T, __start: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ...
|
||||
@@ -375,6 +381,7 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
@overload
|
||||
def pop(self, key: _KT, default: _VT | _T = ...) -> _VT | _T: ...
|
||||
def copy(self: 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`.
|
||||
@classmethod
|
||||
@overload
|
||||
|
||||
@@ -2,7 +2,7 @@ import sys
|
||||
from _typeshed import Self
|
||||
from decimal import Decimal
|
||||
from numbers import Integral, Rational, Real
|
||||
from typing import Union, overload
|
||||
from typing import Any, Union, overload
|
||||
from typing_extensions import Literal
|
||||
|
||||
_ComparableNum = Union[int, float, Decimal, Real]
|
||||
@@ -135,6 +135,8 @@ class Fraction(Rational):
|
||||
def __le__(self, other: _ComparableNum) -> bool: ...
|
||||
def __ge__(self, other: _ComparableNum) -> bool: ...
|
||||
def __bool__(self) -> bool: ...
|
||||
def __copy__(self: Self) -> Self: ...
|
||||
def __deepcopy__(self: Self, memo: Any) -> Self: ...
|
||||
if sys.version_info >= (3, 11):
|
||||
def __int__(self) -> int: ...
|
||||
# Not actually defined within fractions.py, but provides more useful
|
||||
|
||||
@@ -29,6 +29,8 @@ class _lru_cache_wrapper(Generic[_T]):
|
||||
def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T: ...
|
||||
def cache_info(self) -> _CacheInfo: ...
|
||||
def cache_clear(self) -> None: ...
|
||||
def __copy__(self) -> _lru_cache_wrapper[_T]: ...
|
||||
def __deepcopy__(self, __memo: Any) -> _lru_cache_wrapper[_T]: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
|
||||
@@ -635,6 +635,8 @@ class Match(Generic[AnyStr]):
|
||||
def __getitem__(self, __key: _Literal[0]) -> AnyStr: ...
|
||||
@overload
|
||||
def __getitem__(self, __key: int | str) -> AnyStr | Any: ...
|
||||
def __copy__(self) -> Match[AnyStr]: ...
|
||||
def __deepcopy__(self, __memo: Any) -> Match[AnyStr]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
@@ -658,6 +660,8 @@ class Pattern(Generic[AnyStr]):
|
||||
def subn(self, repl: AnyStr, string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ...
|
||||
@overload
|
||||
def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ...
|
||||
def __copy__(self) -> Pattern[AnyStr]: ...
|
||||
def __deepcopy__(self, __memo: Any) -> Pattern[AnyStr]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]):
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[_KT]: ...
|
||||
def copy(self) -> WeakValueDictionary[_KT, _VT]: ...
|
||||
__copy__ = copy
|
||||
def __deepcopy__(self: Self, memo: Any) -> Self: ...
|
||||
# These are incompatible with Mapping
|
||||
def keys(self) -> Iterator[_KT]: ... # type: ignore[override]
|
||||
def values(self) -> Iterator[_VT]: ... # type: ignore[override]
|
||||
@@ -84,6 +86,8 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]):
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[_KT]: ...
|
||||
def copy(self) -> WeakKeyDictionary[_KT, _VT]: ...
|
||||
__copy__ = copy
|
||||
def __deepcopy__(self: Self, memo: Any) -> Self: ...
|
||||
# These are incompatible with Mapping
|
||||
def keys(self) -> Iterator[_KT]: ... # type: ignore[override]
|
||||
def values(self) -> Iterator[_VT]: ... # type: ignore[override]
|
||||
|
||||
@@ -85,9 +85,12 @@ class Element(MutableSequence[Element]):
|
||||
def iterfind(self, path: str, namespaces: dict[str, str] | None = ...) -> Generator[Element, None, None]: ...
|
||||
def itertext(self) -> Generator[str, None, None]: ...
|
||||
def keys(self) -> KeysView[str]: ...
|
||||
# makeelement returns the type of self in Python impl, but not in C impl
|
||||
def makeelement(self, __tag: str, __attrib: dict[str, str]) -> Element: ...
|
||||
def remove(self, __subelement: Element) -> None: ...
|
||||
def set(self, __key: str, __value: str) -> None: ...
|
||||
def __copy__(self) -> Element: ... # returns the type of self in Python impl, but not in C impl
|
||||
def __deepcopy__(self, __memo: Any) -> Element: ... # Only exists in C impl
|
||||
def __delitem__(self, __i: SupportsIndex | slice) -> None: ...
|
||||
@overload
|
||||
def __getitem__(self, __i: SupportsIndex) -> Element: ...
|
||||
|
||||
Reference in New Issue
Block a user