ruff/crates
Dhruv Manilawala b16f665a81
[red-knot] Infer target types for unpacked tuple assignment (#13316)
## Summary

This PR adds support for unpacking tuple expression in an assignment
statement where the target expression can be a tuple or a list (the
allowed sequence targets).

The implementation introduces a new `infer_assignment_target` which can
then be used for other targets like the ones in for loops as well. This
delegates it to the `infer_definition`. The final implementation uses a
recursive function that visits the target expression in source order and
compares the variable node that corresponds to the definition. At the
same time, it keeps track of where it is on the assignment value type.

The logic also accounts for the number of elements on both sides such
that it matches even if there's a gap in between. For example, if
there's a starred expression like `(a, *b, c) = (1, 2, 3)`, then the
type of `a` will be `Literal[1]` and the type of `b` will be
`Literal[2]`.

There are a couple of follow-ups that can be done:
* Use this logic for other target positions like `for` loop
* Add diagnostics for mis-match length between LHS and RHS

## Test Plan

Add various test cases using the new markdown test framework.
Validate that existing test cases pass.

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
2024-10-15 19:07:11 +00:00
..
red_knot Upgrade salsa (#13757) 2024-10-15 11:06:32 +00:00
red_knot_python_semantic [red-knot] Infer target types for unpacked tuple assignment (#13316) 2024-10-15 19:07:11 +00:00
red_knot_server Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
red_knot_test [red-knot] Port type inference tests to new test framework (#13719) 2024-10-15 11:23:46 -07:00
red_knot_vendored Sync vendored typeshed stubs (#13753) 2024-10-15 13:36:11 +00:00
red_knot_wasm Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
red_knot_workspace [red-knot] Infer target types for unpacked tuple assignment (#13316) 2024-10-15 19:07:11 +00:00
ruff Bump version to 0.6.9 (#13624) 2024-10-04 18:51:13 +05:30
ruff_benchmark Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_dev Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_diagnostics [Minor typo] Fix article in "an fix" (#12797) 2024-08-10 21:22:00 -04:00
ruff_formatter Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_graph Upgrade salsa (#13757) 2024-10-15 11:06:32 +00:00
ruff_index [red-knot] small efficiency improvements and bugfixes to use-def map building (#12373) 2024-07-18 09:24:58 -07:00
ruff_linter Fix TODO directive out of bounds acccess (#13756) 2024-10-15 10:49:53 +02:00
ruff_macros Drop deprecated nursery rule group (#10172) 2024-06-27 13:44:11 +02:00
ruff_notebook Allow ipytest cell magic (#13745) 2024-10-14 15:48:33 +05:30
ruff_python_ast Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_python_ast_integration_tests [internal] ComparableExpr (f)strings and bytes made invariant under concatenation (#13301) 2024-09-25 16:58:57 +02:00
ruff_python_codegen Implement iter(), len() and is_empty() for all display-literal AST nodes (#12807) 2024-08-12 10:39:28 +00:00
ruff_python_formatter Remove layout values from AnyStringPart (#13681) 2024-10-09 07:25:40 +01:00
ruff_python_index Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
ruff_python_literal Remove some unused pub functions (#11576) 2024-05-28 09:56:51 -04:00
ruff_python_parser Expose internal types as public access (#13509) 2024-09-26 17:34:30 +02:00
ruff_python_resolver
ruff_python_semantic Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_python_stdlib Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
ruff_python_trivia [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_python_trivia_integration_tests Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
ruff_server Add support for extensionless Python files for server (#13326) 2024-09-12 00:35:26 +05:30
ruff_source_file Fix off-by one error in the LineIndex::offset calculation (#13407) 2024-09-19 11:58:45 +00:00
ruff_text_size [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_wasm Bump version to 0.6.9 (#13624) 2024-10-04 18:51:13 +05:30
ruff_workspace Fix typo in allow-unused-imports documentation (#13669) 2024-10-07 14:08:36 -05:00