mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
Allow use of kwargs in MutableMapping.update (#252)
Discovered while adding MyPy for code that was implementing
MutableMapping and using the update function like this:
```python
class CaseInsensitiveDict(collections.MutableMapping):
def __init__(self, data=None, **kwargs):
# type: (dict, **Any) -> None
self._store = dict() # type: dict
if data is None:
data = {}
self.update(data, **kwargs)
```
This commit adds kwargs to MutableMapping to allow this.
Shout out to Tim Abbott for assisting me with this.
This commit is contained in:
committed by
Guido van Rossum
parent
82b9baed3b
commit
ac9ade5374
@@ -539,9 +539,9 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def popitem(self) -> Tuple[_KT, _VT]: ...
|
||||
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
|
||||
@overload
|
||||
def update(self, m: Mapping[_KT, _VT]) -> None: ...
|
||||
def update(self, m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
|
||||
@overload
|
||||
def update(self, m: Iterable[Tuple[_KT, _VT]]) -> None: ...
|
||||
def update(self, m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
|
||||
def keys(self) -> List[_KT]: ...
|
||||
def values(self) -> List[_VT]: ...
|
||||
def items(self) -> List[Tuple[_KT, _VT]]: ...
|
||||
|
||||
@@ -64,9 +64,9 @@ class Counter(Dict[_T, int], Generic[_T]):
|
||||
# Dict.update. Not sure if we should use '# type: ignore' instead
|
||||
# and omit the type from the union.
|
||||
@overload
|
||||
def update(self, m: Mapping[_T, int]) -> None: ...
|
||||
def update(self, m: Mapping[_T, int], **kwargs: _VT) -> None: ...
|
||||
@overload
|
||||
def update(self, m: Union[Iterable[_T], Iterable[Tuple[_T, int]]]) -> None: ...
|
||||
def update(self, m: Union[Iterable[_T], Iterable[Tuple[_T, int]]], **kwargs: _VT) -> None: ...
|
||||
|
||||
class OrderedDict(Dict[_KT, _VT], Generic[_KT, _VT]):
|
||||
def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ...
|
||||
|
||||
@@ -181,9 +181,9 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def popitem(self) -> Tuple[_KT, _VT]: ...
|
||||
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
|
||||
@overload
|
||||
def update(self, m: Mapping[_KT, _VT]) -> None: ...
|
||||
def update(self, m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
|
||||
@overload
|
||||
def update(self, m: Iterable[Tuple[_KT, _VT]]) -> None: ...
|
||||
def update(self, m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
|
||||
|
||||
Text = unicode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user