[ty] Use key and value parameter types as type context for __setitem__ dunder calls#22148
Merged
ibraheemdev merged 3 commits intomainfrom Jan 12, 2026
Merged
[ty] Use key and value parameter types as type context for __setitem__ dunder calls#22148ibraheemdev merged 3 commits intomainfrom
__setitem__ dunder calls#22148ibraheemdev merged 3 commits intomainfrom
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
|
a244b27 to
ca9593e
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-assignment |
0 | 28 | 9 |
invalid-argument-type |
1 | 12 | 3 |
invalid-await |
2 | 0 | 6 |
invalid-return-type |
0 | 0 | 6 |
possibly-missing-attribute |
3 | 0 | 1 |
unresolved-attribute |
0 | 0 | 2 |
not-subscriptable |
0 | 1 | 0 |
unused-ignore-comment |
0 | 1 | 0 |
| Total | 6 | 42 | 27 |
cc72a35 to
97d313d
Compare
MichaReiser
reviewed
Dec 30, 2025
MichaReiser
reviewed
Dec 30, 2025
db730f9 to
bc245c4
Compare
carljm
approved these changes
Jan 12, 2026
Comment on lines
+4051
to
+4068
| let ast_arguments = [ | ||
| ArgOrKeyword::Arg(&target.slice), | ||
| ArgOrKeyword::Arg(rhs_value_node), | ||
| ]; | ||
|
|
||
| let mut call_arguments = | ||
| CallArguments::positional([Type::unknown(), Type::unknown()]); | ||
|
|
||
| let mut infer_argument_ty = | ||
| |builder: &mut Self, (argument_index, _, tcx): ArgExpr<'db, '_>| { | ||
| match argument_index { | ||
| 0 => infer_slice_ty(builder, tcx), | ||
| 1 => infer_rhs_value(builder, tcx), | ||
| _ => unreachable!(), | ||
| } | ||
| }; | ||
|
|
||
| let Err(call_dunder_err) = self.infer_and_try_call_dunder( |
Contributor
There was a problem hiding this comment.
I think the ergonomics of argument handling for self.infer_and_try_call_dunder could probably be better? But we can defer that to once we have >1 use of it.
Member
Author
There was a problem hiding this comment.
Yeah, it's just a little bit tricky because the underlying method infer_all_argument_types is meant to work with variadic AST arguments, while this case requires a custom inference method per argument. Open to suggestions.
25df5ff to
ddcddab
Compare
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.
Summary
Resolves astral-sh/ty#2136.