Repository navigation
Make Mapping.get(default) more constrained - #14360
Merged
Merged
Conversation
Summary: Test Plan:
Summary: Test Plan:
Summary: Test Plan:
Summary: Test Plan:
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: operator (https://github.com/canonical/operator)
+ ops/model.py:1025: note: def get(self, str, /, default: Binding) -> Binding
+ ops/model.py:1025: note: @overload
- ops/model.py:1025: note: def [_T] get(self, str, /, default: Binding | _T) -> Binding | _T
+ ops/model.py:1025: note: def [_T] get(self, str, /, default: _T) -> Binding | _T
starlette (https://github.com/encode/starlette)
+ starlette/requests.py:137: error: Returning Any from function declared to return "dict[str, Any]" [no-any-return]
django-stubs (https://github.com/typeddjango/django-stubs)
+ django-stubs/utils/datastructures.pyi:65: error: Unused "type: ignore" comment [unused-ignore]
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 [_T] get(self, str, /, default: str | _T) -> str | _T
+ pyodide-build/pyodide_build/xbuildenv_releases.py:220: note: def [_T] get(self, str, /, default: _T) -> str | _T
discord.py (https://github.com/Rapptz/discord.py)
- ...typeshed_to_test/stdlib/typing.pyi:1013: note: "update" of "TypedDict" defined here
+ ...typeshed_to_test/stdlib/typing.pyi:1015: note: "update" of "TypedDict" defined here
- ...typeshed_to_test/stdlib/typing.pyi:1013: note: "update" of "TypedDict" defined here
+ ...typeshed_to_test/stdlib/typing.pyi:1015: note: "update" of "TypedDict" defined here
core (https://github.com/home-assistant/core)
+ homeassistant/components/transmission/coordinator.py:63: error: Returning Any from function declared to return "int" [no-any-return]
+ homeassistant/components/transmission/coordinator.py:68: error: Returning Any from function declared to return "str" [no-any-return]
+ homeassistant/components/islamic_prayer_times/coordinator.py:57: error: Returning Any from function declared to return "str" [no-any-return]
+ homeassistant/components/islamic_prayer_times/coordinator.py:71: error: Returning Any from function declared to return "str" [no-any-return]
+ homeassistant/components/islamic_prayer_times/coordinator.py:76: error: Returning Any from function declared to return "str" [no-any-return]
+ homeassistant/components/bthome/coordinator.py:48: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/androidtv_remote/helpers.py:28: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/xiaomi_ble/coordinator.py:70: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/unifiprotect/data.py:96: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/unifiprotect/data.py:101: error: Returning Any from function declared to return "int" [no-any-return]
+ homeassistant/components/shelly/utils.py:454: error: Returning Any from function declared to return "int" [no-any-return]
+ homeassistant/components/mikrotik/coordinator.py:86: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/mikrotik/coordinator.py:91: error: Returning Any from function declared to return "bool" [no-any-return]
+ homeassistant/components/bthome/device_trigger.py:73: error: Returning Any from function declared to return "list[str]" [no-any-return]
+ homeassistant/components/squeezebox/media_player.py:292: error: Returning Any from function declared to return "int" [no-any-return]
+ homeassistant/components/shelly/coordinator.py:166: error: Returning Any from function declared to return "int" [no-any-return]
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: @overload
- steam/ext/commands/utils.py:43: note: def [_T] get(self, str, /, default: _VT | _T) -> _VT | _T
+ steam/ext/commands/utils.py:43: note: def [_T] get(self, str, /, default: _T) -> _VT | _T
ignite (https://github.com/pytorch/ignite)
+ ignite/handlers/visdom_logger.py:182: error: Redundant cast to "str" [redundant-cast]
|
Contributor
Author
|
Looking at home-assistant/core and encode/starlette these are both approximately: The error is |
hauntsaninja
approved these changes
Jul 2, 2025
hauntsaninja
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, this looks good to me!
facebook-github-bot
pushed a commit
to facebook/pyrefly
that referenced
this pull request
Jul 2, 2025
Summary: Fixes mapping.get as per python/typeshed#14360. Reviewed By: yangdanny97 Differential Revision: D77657698 fbshipit-source-id: 02a17faf5a608a800eb8913a39b28293e452aa36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #14347, with all the tests now passing. Does the same thing as #10294 but using the pattern from #10501 everywhere. Means that the type of Mapping.get now has a type that very clearly returns the default, rather than potentially returning a fresh type that has never been seen before. Makes Pyrefly give more precise types for
os.environ.get("X", "Y").Assuming these commits are squash merged, but can squash in advance if required (the commit history involved a lot of experimenting with CI).