mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 13:34:58 +08:00
WIP: Mapping.{get,pop} can return default type (#223)
* Mapping.{get,pop} can return default type
* Mapping values are covariant
This commit is contained in:
committed by
Guido van Rossum
parent
5b5f01f33c
commit
d43adbe97e
@@ -215,16 +215,19 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
|
||||
|
||||
# TODO: ContextManager (only if contextlib.AbstractContextManager exists)
|
||||
|
||||
class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT]):
|
||||
class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT_co]):
|
||||
# TODO: Value type should be covariant, but currently we can't give a good signature for
|
||||
# get if this is the case.
|
||||
@abstractmethod
|
||||
def __getitem__(self, k: _KT) -> _VT: ...
|
||||
def __getitem__(self, k: _KT) -> _VT_co: ...
|
||||
# Mixin methods
|
||||
def get(self, k: _KT, default: _VT = ...) -> _VT: ...
|
||||
def items(self) -> AbstractSet[Tuple[_KT, _VT]]: ...
|
||||
@overload
|
||||
def get(self, k: _KT) -> Optional[_VT_co]: ...
|
||||
@overload
|
||||
def get(self, k: _KT, default: _T) -> Union[_VT_co, _T]: ...
|
||||
def items(self) -> AbstractSet[Tuple[_KT, _VT_co]]: ...
|
||||
def keys(self) -> AbstractSet[_KT]: ...
|
||||
def values(self) -> ValuesView[_VT]: ...
|
||||
def values(self) -> ValuesView[_VT_co]: ...
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
|
||||
class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
@@ -234,7 +237,10 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def __delitem__(self, v: _KT) -> None: ...
|
||||
|
||||
def clear(self) -> None: ...
|
||||
def pop(self, k: _KT, default: _VT = ...) -> _VT: ...
|
||||
@overload
|
||||
def pop(self, k: _KT) -> _VT: ...
|
||||
@overload
|
||||
def pop(self, k: _KT, default: _T) -> Union[_VT, _T]: ...
|
||||
def popitem(self) -> Tuple[_KT, _VT]: ...
|
||||
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
|
||||
# 'update' used to take a Union, but using overloading is better.
|
||||
|
||||
Reference in New Issue
Block a user