From ac9ade5374ce77bfa618150328b634853648dce9 Mon Sep 17 00:00:00 2001 From: Tim Simpson Date: Sun, 5 Jun 2016 20:10:56 -0500 Subject: [PATCH] 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. --- stdlib/2.7/__builtin__.pyi | 4 ++-- stdlib/2.7/collections.pyi | 4 ++-- stdlib/2.7/typing.pyi | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/2.7/__builtin__.pyi b/stdlib/2.7/__builtin__.pyi index c23c91379..d17e12365 100644 --- a/stdlib/2.7/__builtin__.pyi +++ b/stdlib/2.7/__builtin__.pyi @@ -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]]: ... diff --git a/stdlib/2.7/collections.pyi b/stdlib/2.7/collections.pyi index 0d7182e8f..ac6cb7e5f 100644 --- a/stdlib/2.7/collections.pyi +++ b/stdlib/2.7/collections.pyi @@ -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]: ... diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index 9ea3ed191..0cfeffb60 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -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