Harmonise UserDict.__init__ with dict.__init__ (#6490)

Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
Alex Waygood
2021-12-04 17:50:47 +00:00
committed by GitHub
parent 56c45528b7
commit f105c79219
2 changed files with 14 additions and 3 deletions

View File

@@ -816,6 +816,7 @@ class list(MutableSequence[_T], Generic[_T]):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
# __init__ should be kept roughly in line with `collections.UserDict.__init__`, which has similar semantics
@overload
def __init__(self: dict[_KT, _VT]) -> None: ...
@overload

View File

@@ -1,6 +1,6 @@
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import Self, SupportsLessThan, SupportsLessThanT
from _typeshed import Self, SupportsKeysAndGetItem, SupportsLessThan, SupportsLessThanT
from typing import Any, Dict, Generic, NoReturn, Tuple, Type, TypeVar, overload
from typing_extensions import SupportsIndex, final
@@ -35,9 +35,19 @@ else:
typename: str, field_names: str | Iterable[str], *, verbose: bool = ..., rename: bool = ..., module: str | None = ...
) -> Type[Tuple[Any, ...]]: ...
class UserDict(MutableMapping[_KT, _VT]):
class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
data: dict[_KT, _VT]
def __init__(self, __dict: Mapping[_KT, _VT] | None = ..., **kwargs: _VT) -> None: ...
# __init__ should be kept roughly in line with `dict.__init__`, which has the same semantics
@overload
def __init__(self: UserDict[_KT, _VT], __dict: None = ...) -> None: ...
@overload
def __init__(self: UserDict[str, _VT], __dict: None = ..., **kwargs: _VT) -> None: ...
@overload
def __init__(self, __dict: SupportsKeysAndGetItem[_KT, _VT], **kwargs: _VT) -> None: ...
@overload
def __init__(self, __iterable: Iterable[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
@overload
def __init__(self: UserDict[str, str], __iterable: Iterable[list[str]]) -> None: ...
def __len__(self) -> int: ...
def __getitem__(self, key: _KT) -> _VT: ...
def __setitem__(self, key: _KT, item: _VT) -> None: ...