diff --git a/stdlib/2/builtins.pyi b/stdlib/2/builtins.pyi index 834ea366e82c..d9c2f115abe1 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -535,7 +535,10 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def has_key(self, k: _KT) -> bool: ... def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... - def get(self, k: _KT, default: _VT = None) -> _VT: ... + @overload + def get(self, k: _KT) -> Optional[_VT]: ... + @overload + def get(self, k: _KT, default: _T2) -> Union[_VT, _T2]: ... def pop(self, k: _KT, default: _VT = ...) -> _VT: ... def popitem(self) -> Tuple[_KT, _VT]: ... def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index 035f36eae5b8..c7a6af17501c 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -174,15 +174,17 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]): def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[_VT_co]: ... -class Mapping(Sized, Iterable[_KT], Container[_KT], Generic[_KT, _VT_co]): +class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT_co]): # TODO: We wish the key type could also be covariant, but that doesn't work, # see discussion in https: //github.com/python/typing/pull/273. @abstractmethod def __getitem__(self, k: _KT) -> _VT_co: ... # Mixin methods - def get(self, k: _KT, default: _VT_co = ...) -> _VT_co: # type: ignore - ... + @overload # type: ignore + def get(self, k: _KT) -> Optional[_VT_co]: ... + @overload # type: ignore + def get(self, k: _KT, default: _VT) -> Union[_VT_co, _VT]: ... def keys(self) -> list[_KT]: ... def values(self) -> list[_VT_co]: ... def items(self) -> list[Tuple[_KT, _VT_co]]: ... diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index bfa315b3d6b0..f7ff48a59a1f 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -550,7 +550,10 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... def clear(self) -> None: ... def copy(self) -> Dict[_KT, _VT]: ... - def get(self, k: _KT, default: _VT = None) -> _VT: ... + @overload + def get(self, k: _KT) -> Optional[_VT]: ... + @overload + def get(self, k: _KT, default: _T2) -> Union[_VT, _T2]: ... def pop(self, k: _KT, default: _VT = None) -> _VT: ... def popitem(self) -> Tuple[_KT, _VT]: ... def setdefault(self, k: _KT, default: _VT = None) -> _VT: ... diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 099f92595b72..63a415390d70 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -250,8 +250,10 @@ class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT_co]): def __getitem__(self, k: _KT) -> _VT_co: ... # Mixin methods - def get(self, k: _KT, default: _VT_co = ...) -> _VT_co: # type: ignore - ... + @overload # type: ignore + def get(self, k: _KT) -> Optional[_VT_co]: ... + @overload # type: ignore + def get(self, k: _KT, default: _VT) -> Union[_VT_co, _VT]: ... def items(self) -> AbstractSet[Tuple[_KT, _VT_co]]: ... def keys(self) -> AbstractSet[_KT]: ... def values(self) -> ValuesView[_VT_co]: ...