Use overloading rather than Union for MutableMapping.update (#174)

See https://github.com/python/mypy/issues/1430 for motivation.
This commit is contained in:
rwbarton
2016-05-01 09:50:01 -07:00
committed by Jukka Lehtosalo
parent a5d5dcc4f4
commit 2b80cdf75e
6 changed files with 34 additions and 14 deletions

View File

@@ -531,8 +531,10 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def pop(self, k: _KT, default: _VT = ...) -> _VT: ...
def popitem(self) -> Tuple[_KT, _VT]: ...
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
def update(self, m: Union[Mapping[_KT, _VT],
Iterable[Tuple[_KT, _VT]]]) -> None: ...
@overload
def update(self, m: Mapping[_KT, _VT]) -> None: ...
@overload
def update(self, m: Iterable[Tuple[_KT, _VT]]) -> None: ...
def keys(self) -> List[_KT]: ...
def values(self) -> List[_VT]: ...
def items(self) -> List[Tuple[_KT, _VT]]: ...

View File

@@ -63,9 +63,10 @@ class Counter(Dict[_T, int], Generic[_T]):
# it's included so that the signature is compatible with
# Dict.update. Not sure if we should use '# type: ignore' instead
# and omit the type from the union.
def update(self, m: Union[Mapping[_T, int],
Iterable[Tuple[_T, int]],
Iterable[_T]]) -> None: ...
@overload
def update(self, m: Mapping[_T, int]) -> None: ...
@overload
def update(self, m: Union[Iterable[_T], Iterable[Tuple[_T, int]]]) -> None: ...
class OrderedDict(Dict[_KT, _VT], Generic[_KT, _VT]):
def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ...

View File

@@ -179,8 +179,10 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
def pop(self, k: _KT, default: _VT = ...) -> _VT: ...
def popitem(self) -> Tuple[_KT, _VT]: ...
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
def update(self, m: Union[Mapping[_KT, _VT],
Iterable[Tuple[_KT, _VT]]]) -> None: ...
@overload
def update(self, m: Mapping[_KT, _VT]) -> None: ...
@overload
def update(self, m: Iterable[Tuple[_KT, _VT]]) -> None: ...
Text = unicode