mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-06 21:43:59 +08:00
Forbid keyword arguments for certain Mapping methods (#15085)
This commit is contained in:
+9
-4
@@ -762,6 +762,11 @@ class ValuesView(MappingView, Collection[_VT_co]):
|
||||
def __contains__(self, value: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[_VT_co]: ...
|
||||
|
||||
# note for Mapping.get and MutableMapping.pop and MutableMapping.setdefault
|
||||
# In _collections_abc.py the parameters are positional-or-keyword,
|
||||
# but dict and types.MappingProxyType (the vast majority of Mapping types)
|
||||
# don't allow keyword arguments.
|
||||
|
||||
class Mapping(Collection[_KT], 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.
|
||||
@@ -771,9 +776,9 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
|
||||
@overload
|
||||
def get(self, key: _KT, /) -> _VT_co | None: ...
|
||||
@overload
|
||||
def get(self, key: _KT, /, default: _VT_co) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
|
||||
def get(self, key: _KT, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
|
||||
@overload
|
||||
def get(self, key: _KT, /, default: _T) -> _VT_co | _T: ...
|
||||
def get(self, key: _KT, default: _T, /) -> _VT_co | _T: ...
|
||||
def items(self) -> ItemsView[_KT, _VT_co]: ...
|
||||
def keys(self) -> KeysView[_KT]: ...
|
||||
def values(self) -> ValuesView[_VT_co]: ...
|
||||
@@ -789,9 +794,9 @@ class MutableMapping(Mapping[_KT, _VT]):
|
||||
@overload
|
||||
def pop(self, key: _KT, /) -> _VT: ...
|
||||
@overload
|
||||
def pop(self, key: _KT, /, default: _VT) -> _VT: ...
|
||||
def pop(self, key: _KT, default: _VT, /) -> _VT: ...
|
||||
@overload
|
||||
def pop(self, key: _KT, /, default: _T) -> _VT | _T: ...
|
||||
def pop(self, key: _KT, default: _T, /) -> _VT | _T: ...
|
||||
def popitem(self) -> tuple[_KT, _VT]: ...
|
||||
# This overload should be allowed only if the value type is compatible with None.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user