Skip to content

Better signature for Mapping.get(). #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions stdlib/2.7/UserDict.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import (Any, Container, Dict, Generic, Iterable, Iterator, List,
Mapping, Sized, Tuple, TypeVar, overload)
Mapping, Optional, Sized, Tuple, TypeVar, overload)

_KT = TypeVar('_KT')
_VT = TypeVar('_VT')
Expand All @@ -19,7 +19,10 @@ class DictMixin(Sized, Iterable[_KT], Container[_KT], Generic[_KT, _VT]):

# From typing.Mapping[_KT, _VT]
# (can't inherit because of keys())
def get(self, k: _KT, default: _VT = ...) -> _VT: ...
@overload
def get(self, k: _KT, default: Optional[None] = ...) -> Optional[_VT]: ...
@overload
def get(self, k: _KT, default: _VT) -> _VT: ...
def values(self) -> List[_VT]: ...
def items(self) -> List[Tuple[_KT, _VT]]: ...
def iterkeys(self) -> Iterator[_KT]: ...
Expand Down
6 changes: 5 additions & 1 deletion stdlib/2.7/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,11 @@ 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, default: Optional[None] = ...) -> Optional[_VT]:
...
@overload
def get(self, k: _KT, default: _VT) -> _VT: ...
def pop(self, k: _KT, default: _VT = ...) -> _VT: ...
def popitem(self) -> Tuple[_KT, _VT]: ...
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
Expand Down
6 changes: 5 additions & 1 deletion stdlib/2.7/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ class Mapping(Sized, Iterable[_KT], Container[_KT], 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
def get(self, k: _KT, default: Optional[None] = ...) -> Optional[_VT_co]: # type: ignore
...
@overload # type: ignore
def get(self, k: _KT, default: _VT_co) -> _VT_co: # type: ignore
...
def keys(self) -> list[_KT]: ...
def values(self) -> list[_VT_co]: ...
Expand Down
5 changes: 4 additions & 1 deletion stdlib/3/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,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, default: Optional[None] = ...) -> Optional[_VT]: ...
@overload
def get(self, k: _KT, default: _VT) -> _VT: ...
def pop(self, k: _KT, default: _VT = None) -> _VT: ...
def popitem(self) -> Tuple[_KT, _VT]: ...
def setdefault(self, k: _KT, default: _VT = None) -> _VT: ...
Expand Down
6 changes: 5 additions & 1 deletion stdlib/3/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ 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
def get(self, k: _KT, default: Optional[None] = ...) -> Optional[_VT_co]: # type: ignore
...
@overload # type: ignore
def get(self, k: _KT, default: _VT_co) -> _VT_co: # type: ignore
...
def items(self) -> AbstractSet[Tuple[_KT, _VT_co]]: ...
def keys(self) -> AbstractSet[_KT]: ...
Expand Down