Skip to content

Allow arbitrary types in dict.pop (3 overloads, always object) - #15377

Closed
randolf-scholz wants to merge 2 commits into
python:mainfrom
randolf-scholz:pop_3_overloads_always_object
Closed

Allow arbitrary types in dict.pop (3 overloads, always object)#15377
randolf-scholz wants to merge 2 commits into
python:mainfrom
randolf-scholz:pop_3_overloads_always_object

Conversation

@randolf-scholz

@randolf-scholzrandolf-scholz commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Fixes#15271

See: #15297

Variant that always uses object.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

bidict (https://github.com/jab/bidict)
+ bidict/_bidict.py: note: In member "pop" of class "MutableBidict":+ bidict/_bidict.py:126:6: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ bidict/_bidict.py:126:6: note: Superclass:+ bidict/_bidict.py:126:6: note: @overload+ bidict/_bidict.py:126:6: note: def pop(self, object, /) -> VT+ bidict/_bidict.py:126:6: note: @overload+ bidict/_bidict.py:126:6: note: def pop(self, object, VT, /) -> VT+ bidict/_bidict.py:126:6: note: @overload+ bidict/_bidict.py:126:6: note: def [_T] pop(self, object, _T, /) -> VT | _T+ bidict/_bidict.py:126:6: note: Subclass:+ bidict/_bidict.py:126:6: note: @overload+ bidict/_bidict.py:126:6: note: def pop(self, KT, /) -> VT+ bidict/_bidict.py:126:6: note: @overload+ bidict/_bidict.py:126:6: note: def [DT] pop(self, KT, DT = ..., /) -> VT | DT
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/son.py:126: error: Signature of "pop" incompatible with supertype "builtins.dict" [override]+ bson/son.py:126: note: Superclass:+ bson/son.py:126: note: @overload+ bson/son.py:126: note: def pop(self, object, /) -> _Value+ bson/son.py:126: note: @overload+ bson/son.py:126: note: def pop(self, object, _Value, /) -> _Value+ bson/son.py:126: note: @overload+ bson/son.py:126: note: def [_T] pop(self, object, _T, /) -> _Value | _T+ bson/son.py:126: note: Subclass:+ bson/son.py:126: note: def [_T] pop(self, key: _Key, *args: _Value | _T) -> _Value | _T+ bson/son.py:126: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ bson/son.py:126: note: Superclass:+ bson/son.py:126: note: @overload+ bson/son.py:126: note: def pop(self, object, /) -> _Value+ bson/son.py:126: note: @overload+ bson/son.py:126: note: def pop(self, object, _Value, /) -> _Value+ bson/son.py:126: note: @overload+ bson/son.py:126: note: def [_T] pop(self, object, _T, /) -> _Value | _T+ bson/son.py:126: note: Subclass:+ bson/son.py:126: note: def [_T] pop(self, key: _Key, *args: _Value | _T) -> _Value | _T+ pymongo/common.py:1045: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ pymongo/common.py:1045: note: Superclass:+ pymongo/common.py:1045: note: @overload+ pymongo/common.py:1045: note: def pop(self, object, /) -> Any+ pymongo/common.py:1045: note: @overload+ pymongo/common.py:1045: note: def pop(self, object, Any, /) -> Any+ pymongo/common.py:1045: note: @overload+ pymongo/common.py:1045: note: def [_T] pop(self, object, _T, /) -> Any | _T+ pymongo/common.py:1045: note: Subclass:+ pymongo/common.py:1045: note: def pop(self, key: str, *args: Any, **kwargs: Any) -> Any
pylox (https://github.com/sco1/pylox)
+ pylox/containers/array.py:83: note: def pop(self, object, /) -> Any- pylox/containers/array.py:83: note: def pop(self, Any, /) -> Any+ pylox/containers/array.py:83: note: def pop(self, object, Any, /) -> Any- pylox/containers/array.py:83: note: def pop(self, Any, Any, /) -> Any- pylox/containers/array.py:83: note: def [_T] pop(self, Any, _T, /) -> Any | _T+ pylox/containers/array.py:83: note: def [_T] pop(self, object, _T, /) -> Any | _T
rotki (https://github.com/rotki/rotki)
+ rotkehlchen/chain/aggregator.py:727: error: Unused "type: ignore" comment [unused-ignore]
pyodide (https://github.com/pyodide/pyodide)
+ src/py/_pyodide/_core_docs.py:1151: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ src/py/_pyodide/_core_docs.py:1151: note: Superclass:+ src/py/_pyodide/_core_docs.py:1151: note: @overload+ src/py/_pyodide/_core_docs.py:1151: note: def pop(self, object, /) -> VT+ src/py/_pyodide/_core_docs.py:1151: note: @overload+ src/py/_pyodide/_core_docs.py:1151: note: def pop(self, object, VT, /) -> VT+ src/py/_pyodide/_core_docs.py:1151: note: @overload+ src/py/_pyodide/_core_docs.py:1151: note: def [_T] pop(self, object, _T, /) -> VT | _T+ src/py/_pyodide/_core_docs.py:1151: note: Subclass:+ src/py/_pyodide/_core_docs.py:1151: note: @overload+ src/py/_pyodide/_core_docs.py:1151: note: def pop(self, KT, /) -> VT+ src/py/_pyodide/_core_docs.py:1151: note: @overload+ src/py/_pyodide/_core_docs.py:1151: note: def [T] pop(self, KT, VT | T = ..., /) -> VT | T
django-stubs (https://github.com/typeddjango/django-stubs)
+ django-stubs/contrib/sessions/backends/base.pyi:31: error: Signature of "pop" incompatible with supertype "builtins.dict" [override]+ django-stubs/contrib/sessions/backends/base.pyi:31: note: Superclass:+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, object, /) -> Any+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, object, Any, /) -> Any+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def [_T] pop(self, object, _T, /) -> Any | _T+ django-stubs/contrib/sessions/backends/base.pyi:31: note: Subclass:+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, key: str) -> Any+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, key: str, default: Any) -> Any+ django-stubs/contrib/sessions/backends/base.pyi:31: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ django-stubs/contrib/sessions/backends/base.pyi:31: note: Superclass:+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, object, /) -> Any+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, object, Any, /) -> Any+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def [_T] pop(self, object, _T, /) -> Any | _T+ django-stubs/contrib/sessions/backends/base.pyi:31: note: Subclass:+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, key: str) -> Any+ django-stubs/contrib/sessions/backends/base.pyi:31: note: @overload+ django-stubs/contrib/sessions/backends/base.pyi:31: note: def pop(self, key: str, default: Any) -> Any+ django-stubs/http/request.pyi:202: error: Signature of "pop" incompatible with supertype "builtins.dict" [override]+ django-stubs/http/request.pyi:202: note: Superclass:+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def pop(self, object, /) -> str+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def pop(self, object, str, /) -> str+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def [_T] pop(self, object, _T, /) -> str | _T+ django-stubs/http/request.pyi:202: note: Subclass:+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def pop(self, str | bytes, /) -> Never+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def [_Z] pop(self, str | bytes, str | _Z = ..., /) -> Never+ django-stubs/http/request.pyi:202: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ django-stubs/http/request.pyi:202: note: Superclass:+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def pop(self, object, /) -> str+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def pop(self, object, str, /) -> str+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def [_T] pop(self, object, _T, /) -> str | _T+ django-stubs/http/request.pyi:202: note: Subclass:+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def pop(self, str | bytes, /) -> Never+ django-stubs/http/request.pyi:202: note: @overload+ django-stubs/http/request.pyi:202: note: def [_Z] pop(self, str | bytes, str | _Z = ..., /) -> Never
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/datatypes.py:98: error: Signature of "pop" incompatible with supertype "builtins.dict" [override]+ scrapy/utils/datatypes.py:98: note: Superclass:+ scrapy/utils/datatypes.py:98: note: @overload+ scrapy/utils/datatypes.py:98: note: def pop(self, object, /) -> Any+ scrapy/utils/datatypes.py:98: note: @overload+ scrapy/utils/datatypes.py:98: note: def pop(self, object, Any, /) -> Any+ scrapy/utils/datatypes.py:98: note: @overload+ scrapy/utils/datatypes.py:98: note: def [_T] pop(self, object, _T, /) -> Any | _T+ scrapy/utils/datatypes.py:98: note: Subclass:+ scrapy/utils/datatypes.py:98: note: def [AnyStr: (str, bytes)] pop(self, key: AnyStr, *args: Any) -> Any+ scrapy/utils/datatypes.py:98: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ scrapy/utils/datatypes.py:98: note: Superclass:+ scrapy/utils/datatypes.py:98: note: @overload+ scrapy/utils/datatypes.py:98: note: def pop(self, object, /) -> Any+ scrapy/utils/datatypes.py:98: note: @overload+ scrapy/utils/datatypes.py:98: note: def pop(self, object, Any, /) -> Any+ scrapy/utils/datatypes.py:98: note: @overload+ scrapy/utils/datatypes.py:98: note: def [_T] pop(self, object, _T, /) -> Any | _T+ scrapy/utils/datatypes.py:98: note: Subclass:+ scrapy/utils/datatypes.py:98: note: def [AnyStr: (str, bytes)] pop(self, key: AnyStr, *args: Any) -> Any+ scrapy/settings/__init__.py:629: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ scrapy/settings/__init__.py:629: note: Superclass:+ scrapy/settings/__init__.py:629: note: @overload+ scrapy/settings/__init__.py:629: note: def pop(self, object, /) -> Any+ scrapy/settings/__init__.py:629: note: @overload+ scrapy/settings/__init__.py:629: note: def pop(self, object, Any, /) -> Any+ scrapy/settings/__init__.py:629: note: @overload+ scrapy/settings/__init__.py:629: note: def [_T] pop(self, object, _T, /) -> Any | _T+ scrapy/settings/__init__.py:629: note: Subclass:+ scrapy/settings/__init__.py:629: note: def pop(self, name: bool | float | int | str | None, default: Any = ...) -> Any
pylint (https://github.com/pycqa/pylint)
+ pylint/config/arguments_provider.py:54: error: Incompatible types in "yield" (actual type "tuple[None, list[tuple[str, dict[str, str | bool | int | Pattern[str] | Iterable[str | int | Pattern[str]] | type[_CallbackAction] | Callable[[Any], Any] | Callable[[Any, Any, Any, Any], Any] | None], Any]]]", expected type "tuple[str, list[tuple[str, dict[str, str | bool | int | Pattern[str] | Iterable[str | int | Pattern[str]] | type[_CallbackAction] | Callable[[Any], Any] | Callable[[Any, Any, Any, Any], Any] | None], Any]]] | tuple[None, dict[str, list[tuple[str, dict[str, str | bool | int | Pattern[str] | Iterable[str | int | Pattern[str]] | type[_CallbackAction] | Callable[[Any], Any] | Callable[[Any, Any, Any, Any], Any] | None], Any]]]]") [misc]+ pylint/config/arguments_provider.py:54: note: Error code "misc" not covered by "type: ignore" comment+ pylint/config/arguments_provider.py:54: error: Unused "type: ignore" comment [unused-ignore]
discord.py (https://github.com/Rapptz/discord.py)
+ discord/ui/view.py:932: error: Unused "type: ignore" comment [unused-ignore]
steam.py (https://github.com/Gobot1234/steam.py)
+ steam/utils.py:559: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ steam/utils.py:559: note: Superclass:+ steam/utils.py:559: note: @overload+ steam/utils.py:559: note: def pop(self, object, /) -> _VT+ steam/utils.py:559: note: @overload+ steam/utils.py:559: note: def pop(self, object, _VT, /) -> _VT+ steam/utils.py:559: note: @overload+ steam/utils.py:559: note: def [_T] pop(self, object, _T, /) -> _VT | _T+ steam/utils.py:559: note: Subclass:+ steam/utils.py:559: note: @overload+ steam/utils.py:559: note: def pop(self, key: _KT) -> _VT+ steam/utils.py:559: note: @overload+ steam/utils.py:559: note: def [_T] pop(self, key: _KT, default: _VT | _T) -> _VT | _T- steam/ext/commands/utils.py:52: note: def pop(self, str, /) -> _VT+ steam/ext/commands/utils.py:52: note: def pop(self, object, /) -> _VT- steam/ext/commands/utils.py:52: note: def pop(self, str, _VT, /) -> _VT+ steam/ext/commands/utils.py:52: note: def pop(self, object, _VT, /) -> _VT- steam/ext/commands/utils.py:52: note: def [_T] pop(self, str, _T, /) -> _VT | _T+ steam/ext/commands/utils.py:52: note: def [_T] pop(self, object, _T, /) -> _VT | _T- steam/ext/commands/utils.py:52: note: def pop(self, str, /) -> _VT+ steam/ext/commands/utils.py:52: note: def pop(self, object, /) -> _VT- steam/ext/commands/utils.py:52: note: def pop(self, str, _VT, /) -> _VT+ steam/ext/commands/utils.py:52: note: def pop(self, object, _VT, /) -> _VT- steam/ext/commands/utils.py:52: note: def [_T] pop(self, str, _T, /) -> _VT | _T+ steam/ext/commands/utils.py:52: note: def [_T] pop(self, object, _T, /) -> _VT | _T
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/datastructures/mixins.py:265: error: Signature of "pop" incompatible with supertype "builtins.dict" [override]+ src/werkzeug/datastructures/mixins.py:265: note: Superclass:+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, object, /) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, object, V, /) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def [_T] pop(self, object, _T, /) -> V | _T+ src/werkzeug/datastructures/mixins.py:265: note: Subclass:+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, key: K) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, key: K, default: V) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def [T] pop(self, key: K, default: T) -> T+ src/werkzeug/datastructures/mixins.py:265: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ src/werkzeug/datastructures/mixins.py:265: note: Superclass:+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, object, /) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, object, V, /) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def [_T] pop(self, object, _T, /) -> V | _T+ src/werkzeug/datastructures/mixins.py:265: note: Subclass:+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, key: K) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def pop(self, key: K, default: V) -> V+ src/werkzeug/datastructures/mixins.py:265: note: @overload+ src/werkzeug/datastructures/mixins.py:265: note: def [T] pop(self, key: K, default: T) -> T+ src/werkzeug/datastructures/structures.py:469: error: Signature of "pop" incompatible with supertype "builtins.dict" [override]+ src/werkzeug/datastructures/structures.py:469: note: Superclass:+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, object, /) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, object, V, /) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def [_T] pop(self, object, _T, /) -> V | _T+ src/werkzeug/datastructures/structures.py:469: note: Subclass:+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, key: K) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, key: K, default: V) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def [T] pop(self, key: K, default: T) -> V | T+ src/werkzeug/datastructures/structures.py:469: error: Signature of "pop" incompatible with supertype "typing.MutableMapping" [override]+ src/werkzeug/datastructures/structures.py:469: note: Superclass:+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, object, /) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, object, V, /) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def [_T] pop(self, object, _T, /) -> V | _T+ src/werkzeug/datastructures/structures.py:469: note: Subclass:+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, key: K) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def pop(self, key: K, default: V) -> V+ src/werkzeug/datastructures/structures.py:469: note: @overload+ src/werkzeug/datastructures/structures.py:469: note: def [T] pop(self, key: K, default: T) -> V | T
operator (https://github.com/canonical/operator)
- ops/_private/harness.py:2645: error: No overload variant of "pop" of "dict" matches argument types "str", "None" [call-overload]- ops/_private/harness.py:2645: note: Possible overload variants:- ops/_private/harness.py:2645: note: def pop(self, int, /) -> dict[str, Any]- ops/_private/harness.py:2645: note: def pop(self, int, dict[str, Any], /) -> dict[str, Any]- ops/_private/harness.py:2645: note: def [_T] pop(self, int, _T, /) -> dict[str, Any] | _T

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Several methods on built-in types are too strict.

1 participant

@randolf-scholz