You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As #13316 is merged, there are some follow-up work that needs to be done. The following is a list in the order of priority where the highest priority work is on the top:
Avoiding duplicate diagnostics. Considering (a, b) = (1, 2), as the inference runs for each symbol, if there are any diagnostics that's raised during that part (like "too many values to unpack"), then there will be multiple diagnostics added to the builder one for each symbol. Refer [red-knot] Infer target types for unpacked tuple assignment #13316 (comment)
Use the unpacking logic in other places where it's relevant like
for loops e.g., for (x, y) in ((1, 2), (3, 4)): ...
with statements e.g., with (item1, item2) as (x, y): ...
Comprehensions e.g., [_ for (x, y) in [(1, 2), (3, 4)]]
Combine starred element types. For example, in (a, *b, c) = (1, 2, 3, 4), the Literal[2] and Literal[3] type should be combined into list[int] to be assigned to *b. (Requires generic support over list)
## Summary
This PR adds a new salsa query and an ingredient to resolve all the
variables involved in an unpacking assignment like `(a, b) = (1, 2)` at
once. Previously, we'd recursively try to match the correct type for
each definition individually which will result in creating duplicate
diagnostics.
This PR still doesn't solve the duplicate diagnostics issue because that
requires a different solution like using salsa accumulator or
de-duplicating the diagnostics manually.
Related: #13773
## Test Plan
Make sure that all unpack assignment test cases pass, there are no
panics in the corpus tests.
## Todo
- [x] Look at the performance regression
Regarding "Use the unpacking logic in other places where it's relevant like" task, I think the challenge here would be to implement the logic to "combine" union types into a single type. For example, in a for loop like:
As #13316 is merged, there are some follow-up work that needs to be done. The following is a list in the order of priority where the highest priority work is on the top:
(a, b) = (1, 2)
, as the inference runs for each symbol, if there are any diagnostics that's raised during that part (like "too many values to unpack"), then there will be multiple diagnostics added to the builder one for each symbol. Refer [red-knot] Infer target types for unpacked tuple assignment #13316 (comment)for
loops e.g.,for (x, y) in ((1, 2), (3, 4)): ...
with
statements e.g.,with (item1, item2) as (x, y): ...
[_ for (x, y) in [(1, 2), (3, 4)]]
(a, *b, c) = (1, 2, 3, 4)
, theLiteral[2]
andLiteral[3]
type should be combined intolist[int]
to be assigned to*b
. (Requires generic support over list)ruff/crates/red_knot_python_semantic/src/types/infer.rs
Lines 1248 to 1251 in c6b311c
The text was updated successfully, but these errors were encountered: