Skip to content

Conversation

@beauxq
Copy link
Contributor

@beauxq beauxq commented Nov 25, 2025

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
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
Copy link
Contributor Author

beauxq commented Nov 25, 2025

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

The others just look like changes to existing messages.

Copy link
Collaborator

@srittau srittau left a comment

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()?

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