Skip to content

make the default positional-or-keyword in Mapping.get and MutableMapping.pop #6694

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

Merged
merged 4 commits into from
Jan 22, 2022
Merged
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
9 changes: 9 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,15 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
@classmethod
@overload
def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> dict[_T, _S]: ...
# Positional-only in dict, but not in MutableMapping
@overload
def get(self, __key: _KT) -> _VT | None: ...
@overload
def get(self, __key: _KT, __default: _VT | _T) -> _VT | _T: ...
@overload
def pop(self, __key: _KT) -> _VT: ...
@overload
def pop(self, __key: _KT, __default: _VT | _T = ...) -> _VT | _T: ...
def __len__(self) -> int: ...
def __getitem__(self, __k: _KT) -> _VT: ...
def __setitem__(self, __k: _KT, v: _VT) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
def __getitem__(self, __k: _KT) -> _VT_co: ...
# Mixin methods
@overload
def get(self, key: _KT) -> _VT_co | None: ...
def get(self, __key: _KT) -> _VT_co | None: ...
@overload
def get(self, __key: _KT, __default: _VT_co | _T) -> _VT_co | _T: ...
def get(self, __key: _KT, default: _VT_co | _T) -> _VT_co | _T: ...
def items(self) -> ItemsView[_KT, _VT_co]: ...
def keys(self) -> KeysView[_KT]: ...
def values(self) -> ValuesView[_VT_co]: ...
Expand All @@ -468,7 +468,7 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def pop(self, __key: _KT) -> _VT: ...
@overload
def pop(self, __key: _KT, __default: _VT | _T) -> _VT | _T: ...
def pop(self, __key: _KT, default: _VT | _T) -> _VT | _T: ...
def popitem(self) -> tuple[_KT, _VT]: ...
# This overload should be allowed only if the value type is compatible with None.
@overload
Expand Down