mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
Harmonise UserDict.__init__ with dict.__init__ (#6490)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user