mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
Improve several stdlib setdefault methods (#9612)
This commit is contained in:
@@ -602,9 +602,13 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def pop(self, __key: _KT, default: _VT | _T) -> _VT | _T: ...
|
||||
def popitem(self) -> tuple[_KT, _VT]: ...
|
||||
# This overload should be allowed only if the value type is compatible with None.
|
||||
# Keep OrderedDict.setdefault in line with MutableMapping.setdefault, modulo positional-only differences.
|
||||
#
|
||||
# Keep the following methods in line with MutableMapping.setdefault, modulo positional-only differences:
|
||||
# -- collections.OrderedDict.setdefault
|
||||
# -- collections.ChainMap.setdefault
|
||||
# -- weakref.WeakKeyDictionary.setdefault
|
||||
@overload
|
||||
def setdefault(self: MutableMapping[_KT, _T | None], __key: _KT) -> _T | None: ...
|
||||
def setdefault(self: MutableMapping[_KT, _T | None], __key: _KT, __default: None = None) -> _T | None: ...
|
||||
@overload
|
||||
def setdefault(self, __key: _KT, __default: _VT) -> _VT: ...
|
||||
# 'update' used to take a Union, but using overloading is better.
|
||||
|
||||
Reference in New Issue
Block a user