feat: support nested tuple unpacking in assignments (e.g., a, (b, c) …#458
feat: support nested tuple unpacking in assignments (e.g., a, (b, c) …#458Deadpool2000 wants to merge 9 commits intospylang:mainfrom
Conversation
antocuni
left a comment
There was a problem hiding this comment.
thank you @Deadpool2000.
The PR looks mostly good but it lacks many tests, see the inline comments.
Can I ask you how did you find this issue to work on?
Also, can you please confirm that you didn't use any AI code assistant as I requested?
|
Hey @antocuni ! I've gone through all your suggestions and cleaned up the implementation. Here’s a breakdown of what I've done:
To answer your questions: I found this issue while browsing the repository looking for ways to contribute to the compiler's tuple support. Regarding the AI assistant - I did use one to help me speed up the generation of some of the more repetitive unit tests and boilerplate code once I had the core logic figured out. I've manually reviewed and refined everything to ensure it follow the project's style and logic, though. Let me know if there’s anything else! |
Hi! @antocuni I’ve implemented support for nested tuple unpacking in assignments (e.g.,
a, (b, c) = tup). Previously, the parser would hit anAssertionErrorbecause it only expected simple names as unpacking targets.What's changed?
Basically, I've updated the compiler pipeline to handle unpacking targets recursively. Here's the breakdown:
spy/parser.pyto recursively parsepy_ast.Tuplenodes in assignments. It now correctly builds a nested SPy AST instead of crashing.UnpackAssignnode more flexible so it can hold nested expressions (like sub-tuples) as targets.ScopeAnalyzerso it can "see" variables hidden inside nested tuples, making sure they get correctly declared and captured.astframe.pyto handle these nested targets by recursively triggering unpacking operations.Testing
I added a new test file,
spy/tests/compiler/test_nested_unpack.py, which covers:a, (b, c) = tup)a, (b, (c, d)) = tup)(a, b), (c, d) = tup)I've verified that all 9 new test cases pass across the
interp,doppler, andCexecution modes, and I also checked for regressions in the existing tuple tests.Looking forward to your feedback!