mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
Add defaultdict.__(r)or__; improve ChainMap.__(r)or__ and UserDict.__(r)or__ (#10427)
Add __or__ to defaultdict Also, add overloads with Self type to other __[r]or__ methods.
This commit is contained in:
@@ -1102,7 +1102,13 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
|
||||
@overload
|
||||
def __or__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
|
||||
@overload
|
||||
def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
|
||||
@overload
|
||||
def __ror__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
|
||||
@overload
|
||||
def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
|
||||
# dict.__ior__ should be kept roughly in line with MutableMapping.update()
|
||||
@overload # type: ignore[misc]
|
||||
|
||||
@@ -83,8 +83,14 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
@overload
|
||||
def fromkeys(cls, iterable: Iterable[_T], value: _S) -> UserDict[_T, _S]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
@overload
|
||||
def __or__(self, other: UserDict[_KT, _VT] | dict[_KT, _VT]) -> Self: ...
|
||||
@overload
|
||||
def __or__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ...
|
||||
def __ror__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc]
|
||||
@overload # type: ignore[misc]
|
||||
def __ror__(self, other: UserDict[_KT, _VT] | dict[_KT, _VT]) -> Self: ...
|
||||
@overload # type: ignore[misc]
|
||||
def __ror__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ...
|
||||
# UserDict.__ior__ should be kept roughly in line with MutableMapping.update()
|
||||
@overload # type: ignore[misc]
|
||||
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
|
||||
@@ -391,6 +397,15 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
|
||||
def __missing__(self, __key: _KT) -> _VT: ...
|
||||
def __copy__(self) -> Self: ...
|
||||
def copy(self) -> Self: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
@overload
|
||||
def __or__(self, __value: Mapping[_KT, _VT]) -> Self: ...
|
||||
@overload
|
||||
def __or__(self, __value: Mapping[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ...
|
||||
@overload
|
||||
def __ror__(self, __value: Mapping[_KT, _VT]) -> Self: ...
|
||||
@overload
|
||||
def __ror__(self, __value: Mapping[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ...
|
||||
|
||||
class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
maps: list[MutableMapping[_KT, _VT]]
|
||||
@@ -425,7 +440,13 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
@overload
|
||||
def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> ChainMap[_T, _S]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
@overload
|
||||
def __or__(self, other: Mapping[_KT, _VT]) -> Self: ...
|
||||
@overload
|
||||
def __or__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ...
|
||||
@overload
|
||||
def __ror__(self, other: Mapping[_KT, _VT]) -> Self: ...
|
||||
@overload
|
||||
def __ror__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ...
|
||||
# ChainMap.__ior__ should be kept roughly in line with MutableMapping.update()
|
||||
@overload # type: ignore[misc]
|
||||
|
||||
Reference in New Issue
Block a user