Support starred and iterable unpacking in assignments#2556
Open
himanshu748 wants to merge 1 commit into
Open
Conversation
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.
Fixes #2555.
What happens today
Several standard unpacking forms that models write constantly are rejected by the local executor, with errors that point nowhere:
set_valueonly handledast.Tupletargets: it required an exact length match (so any starred target failed the size check), it excludedstr/bytesfrom the iterable path (so string unpacking was refused), and it had noast.Listbranch at all (so[a, b] = ...was silently dropped). The model gets no signal that*targets simply are not implemented, so it retries the same valid code.The fix
Rewrite the tuple/list target branch to match CPython:
a, *b,*a, b,a, *b, c)ast.Listtargets alongsideast.Tuplenot enough values to unpack (expected N, got M),too many values to unpack (expected N),not enough values to unpack (expected at least N, got M),cannot unpack non-iterable X object, andmultiple starred expressions in assignmentNested targets (
a, (b, c) = 1, (2, 3)) keep working through the existing recursion.Tests
14 new parametrized cases covering starred unpacking in every position, empty-star, string/list-pattern/nested unpacking, and the four error messages. One existing test (
test_evaluate_assign_error) was updated from the old "Cannot unpack tuple of wrong size" wording to the new CPython message. All new cases fail on currentmain. Full test file: 411 passed, 2 skipped. Ruff check and format are clean.