Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
More precise return types forTypedDict.get#19897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
ilevkivskyi merged 15 commits intopython:masterfromrandolf-scholz:special_case_typeddict_getOct 14, 2025
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
15 commits Select commitHold shift + click to select a range
27e50e2 improved TypedDict.get inference
randolf-scholze708813 use original DictExpr test isntead of type-based
randolf-scholz63224f2 removed second overload
randolf-scholz808f593 added unit test for 19902
randolf-scholzde8effe Clarify overload comments in checkmember.py
randolf-scholz4ebe192 check total/non-toal against union of keys
randolf-scholza9d2388 added incremental test
randolf-scholz16c97ba use appropriate namespace for TypedDict.get variable
randolf-scholz628a0be Merge branch 'master' into special_case_typeddict_get
randolf-scholz443f6c7 Merge branch 'master' into special_case_typeddict_get
randolf-scholz6bf9401 Merge branch 'master' into special_case_typeddict_get
randolf-scholzcbbbd4d Merge branch 'master' into special_case_typeddict_get
randolf-scholz63f4975 revert reveal_type changes
randolf-scholzf3e8556 Merge branch 'master' into special_case_typeddict_get
randolf-scholza0fbcee Remove extra whitespace
ilevkivskyiFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
revert reveal_type changes
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit63f49759f40316d2ef7ea1ad4c02199fa3bee92f
There are no files selected for viewing
2 changes: 1 addition & 1 deletionmypy/checkexpr.py
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
72 changes: 0 additions & 72 deletionsmypy/checkmember.py
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
46 changes: 43 additions & 3 deletionsmypy/plugins/default.py
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
36 changes: 22 additions & 14 deletionstest-data/unit/check-typeddict.test
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1007,12 +1007,12 @@ class D(TypedDict): | ||
| b: NotRequired[str] | ||
| def test(d: D) -> None: | ||
| reveal_type(d.get) # N: Revealed type is"Overload(def (k: builtins.str) -> builtins.object, def (builtins.str, builtins.object) -> builtins.object, def [V] (builtins.str, V`4) -> builtins.object)" | ||
| [builtins fixtures/dict.pyi] | ||
| [typing fixtures/typing-typeddict.pyi] | ||
| @@ -1155,21 +1155,29 @@ reveal_type(d.get('x', a)) # N: Revealed type is "Union[builtins.list[builtins.i | ||
| from typing import TypedDict | ||
| D = TypedDict('D', {'x': int, 'y': str}) | ||
| d: D | ||
| d.get() # E: All overload variants of "get"of "Mapping"require at least one argument \ | ||
| # N: Possible overload variants: \ | ||
| # N: def get(self, k: str) ->object \ | ||
| # N: def get(self, str, object, /) ->object \ | ||
| # N: def[V]get(self,str,V, /) -> object | ||
| d.get('x', 1, 2) # E: No overload variant of "get"of "Mapping"matches argument types "str", "int", "int" \ | ||
| # N: Possible overload variants: \ | ||
| # N: def get(self, k: str) ->object \ | ||
| # N: def get(self, str, object, /) ->object \ | ||
| # N: def[V]get(self,str,Union[int, V], /) -> object | ||
| x = d.get('z') | ||
| reveal_type(x) # N: Revealed type is "builtins.object" | ||
| s = '' | ||
| y = d.get(s) | ||
| reveal_type(y) # N: Revealed type is "builtins.object" | ||
ilevkivskyi marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| [builtins fixtures/dict.pyi] | ||
| [typing fixtures/typing-typeddict.pyi] | ||
4 changes: 3 additions & 1 deletiontest-data/unit/fixtures/typing-typeddict.pyi
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
18 changes: 8 additions & 10 deletionstest-data/unit/pythoneval.test
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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.