stdlib: Add several missing __(deep)copy__ methods (#7242)

This commit is contained in:
Alex Waygood
2022-02-17 02:57:41 +00:00
committed by GitHub
parent d869f2e5a3
commit 1091521f60
7 changed files with 26 additions and 2 deletions

View File

@@ -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