Skip to content

no keyword arguments for certain mapping methods - #15085

Merged
srittau merged 1 commit into
python:mainfrom
beauxq:mapping-default
Dec 2, 2025
Merged

srittau merged 1 commit into
python:mainfrom
beauxq:mapping-default

Conversation

@beauxq

@beauxq beauxq commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

addresses #13432

implementing what was suggested by Jelle here #13432 (comment)

In making this change, I found that we were already lying about the positional-only information for the key parameter,
(key is also positional-or-keyword in _collections_abc.py)
and both the key and default parameters of MutableMapping.setdefault

So this is also adding consistency.

@github-actions

Copy link
Copy Markdown
Contributor

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

pyodide (https://github.com/pyodide/pyodide)
- pyodide-build/pyodide_build/xbuildenv_releases.py:220: note:     def get(self, str, /, default: str) -> str
+ pyodide-build/pyodide_build/xbuildenv_releases.py:220: note:     def get(self, str, str, /) -> str
- pyodide-build/pyodide_build/xbuildenv_releases.py:220: note:     def [_T] get(self, str, /, default: _T) -> str | _T
+ pyodide-build/pyodide_build/xbuildenv_releases.py:220: note:     def [_T] get(self, str, _T, /) -> str | _T

starlette (https://github.com/encode/starlette)
+ tests/test_datastructures.py:171: error: No overload variant of "get" of "Mapping" matches argument types "str", "None"  [call-overload]
+ tests/test_datastructures.py:171: note: Possible overload variants:
+ tests/test_datastructures.py:171: note:     def get(self, str, /) -> str | None
+ tests/test_datastructures.py:171: note:     def get(self, str, str, /) -> str
+ tests/test_datastructures.py:171: note:     def [_T] get(self, str, _T, /) -> str | _T
+ tests/test_datastructures.py:287: error: No overload variant of "get" of "Mapping" matches argument types "str", "None"  [call-overload]
+ tests/test_datastructures.py:287: note: Possible overload variants:
+ tests/test_datastructures.py:287: note:     def get(self, str, /) -> str | None
+ tests/test_datastructures.py:287: note:     def get(self, str, str, /) -> str
+ tests/test_datastructures.py:287: note:     def [_T] get(self, str, _T, /) -> str | _T
+ tests/test_datastructures.py:371: error: No overload variant of "get" of "Mapping" matches argument types "str", "None"  [call-overload]
+ tests/test_datastructures.py:371: note: Possible overload variants:
+ tests/test_datastructures.py:371: note:     def get(self, str, /) -> UploadFile | str | None
+ tests/test_datastructures.py:371: note:     def get(self, str, UploadFile | str, /) -> UploadFile | str
+ tests/test_datastructures.py:371: note:     def [_T] get(self, str, _T, /) -> UploadFile | str | _T
+ tests/test_datastructures.py:406: error: No overload variant of "get" of "Mapping" matches argument types "str", "None"  [call-overload]
+ tests/test_datastructures.py:406: note: Possible overload variants:
+ tests/test_datastructures.py:406: note:     def get(self, Any, /) -> Any | None
+ tests/test_datastructures.py:406: note:     def get(self, Any, Any, /) -> Any
+ tests/test_datastructures.py:406: note:     def [_T] get(self, Any, _T, /) -> Any | _T

discord.py (https://github.com/Rapptz/discord.py)
- ...typeshed_to_test/stdlib/typing.pyi:1040: note: "update" of "TypedDict" defined here
+ ...typeshed_to_test/stdlib/typing.pyi:1045: note: "update" of "TypedDict" defined here

steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/utils.py:43: note:          def get(self, str, /, default: _VT) -> _VT
+ steam/ext/commands/utils.py:43: note:          def get(self, str, _VT, /) -> _VT
- steam/ext/commands/utils.py:43: note:          def [_T] get(self, str, /, default: _T) -> _VT | _T
+ steam/ext/commands/utils.py:43: note:          def [_T] get(self, str, _T, /) -> _VT | _T
- steam/ext/commands/utils.py:52: note:          def pop(self, str, /, default: _VT) -> _VT
+ steam/ext/commands/utils.py:52: note:          def pop(self, str, _VT, /) -> _VT
- steam/ext/commands/utils.py:52: note:          def [_T] pop(self, str, /, default: _T) -> _VT | _T
+ steam/ext/commands/utils.py:52: note:          def [_T] pop(self, str, _T, /) -> _VT | _T

operator (https://github.com/canonical/operator)
- ops/model.py:1016: note:          def get(self, str, /, default: Binding) -> Binding
+ ops/model.py:1016: note:          def get(self, str, Binding, /) -> Binding
- ops/model.py:1016: note:          def [_T] get(self, str, /, default: _T) -> Binding | _T
+ ops/model.py:1016: note:          def [_T] get(self, str, _T, /) -> Binding | _T

@beauxq

beauxq commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

It looks like Starlette's unit tests are the only new issue from mypy primer.

The others just look like changes to existing messages.

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, primer does indeed look surprisingly decent.

Can you also try to remove the # type: ignore and associated comment from dict.get()?

@beauxq

beauxq commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

Can you also try to remove the # type: ignore and associated comment from dict.get()?

That's a different issue. The covariant type in the contra position is still an issue.

Sign up for free to 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.

2 participants