Skip to content

Commit 11b39b8

Browse files
authored
Forbid keyword arguments for certain Mapping methods (#15085)
1 parent cb592d4 commit 11b39b8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

stdlib/typing.pyi

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,11 @@ class ValuesView(MappingView, Collection[_VT_co]):
762762
def __contains__(self, value: object) -> bool: ...
763763
def __iter__(self) -> Iterator[_VT_co]: ...
764764

765+
# note for Mapping.get and MutableMapping.pop and MutableMapping.setdefault
766+
# In _collections_abc.py the parameters are positional-or-keyword,
767+
# but dict and types.MappingProxyType (the vast majority of Mapping types)
768+
# don't allow keyword arguments.
769+
765770
class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
766771
# TODO: We wish the key type could also be covariant, but that doesn't work,
767772
# see discussion in https://github.com/python/typing/pull/273.
@@ -771,9 +776,9 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
771776
@overload
772777
def get(self, key: _KT, /) -> _VT_co | None: ...
773778
@overload
774-
def get(self, key: _KT, /, default: _VT_co) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
779+
def get(self, key: _KT, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
775780
@overload
776-
def get(self, key: _KT, /, default: _T) -> _VT_co | _T: ...
781+
def get(self, key: _KT, default: _T, /) -> _VT_co | _T: ...
777782
def items(self) -> ItemsView[_KT, _VT_co]: ...
778783
def keys(self) -> KeysView[_KT]: ...
779784
def values(self) -> ValuesView[_VT_co]: ...
@@ -789,9 +794,9 @@ class MutableMapping(Mapping[_KT, _VT]):
789794
@overload
790795
def pop(self, key: _KT, /) -> _VT: ...
791796
@overload
792-
def pop(self, key: _KT, /, default: _VT) -> _VT: ...
797+
def pop(self, key: _KT, default: _VT, /) -> _VT: ...
793798
@overload
794-
def pop(self, key: _KT, /, default: _T) -> _VT | _T: ...
799+
def pop(self, key: _KT, default: _T, /) -> _VT | _T: ...
795800
def popitem(self) -> tuple[_KT, _VT]: ...
796801
# This overload should be allowed only if the value type is compatible with None.
797802
#

0 commit comments

Comments
 (0)