Skip to content

Commit a56bd36

Browse files
added comments to dict.pop and MutableMapping.pop
1 parent 99bdec9 commit a56bd36

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

stdlib/builtins.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,8 @@ class dict(MutableMapping[_KT, _VT]):
12251225
def get(self, key: _KT, default: _VT, /) -> _VT: ...
12261226
@overload
12271227
def get(self, key: _KT, default: _T, /) -> _VT | _T: ...
1228+
# dict.pop allows arbitrary types, which matches runtime semantics.
1229+
# linters may choose to warn if the given type does not overlap with the key type
12281230
@overload
12291231
def pop(self, key: object, /) -> _VT: ...
12301232
@overload

stdlib/typing.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ class MutableMapping(Mapping[_KT, _VT]):
794794
@abstractmethod
795795
def __delitem__(self, key: _KT, /) -> None: ...
796796
def clear(self) -> None: ...
797+
# We annotate this with `Any` rather than `object` as in dict.pop, since
798+
# specific implementations of `MutableMapping` may wish to restrict the type.
797799
@overload
798800
def pop(self, key: Any, /) -> _VT: ...
799801
@overload

0 commit comments

Comments
 (0)