Repository navigation
fix: parse splats in return expression lists - #354
JarvisDing-sdu wants to merge 1 commit into
Conversation
|
I wonder if there is anything special about such expressions appearing in a return statement? x = 1, *([None] * 5)
print(x)Note: I'm not a maintainer here, and this grammar seems to be mostly unmaintained (as many other grammars in this organizations), but we are maintaining a fork tree-sitter-python-orchard, where I would integrate your contribution. |
|
After reviewing the other PRs in this repo, I found #320 which seems to address the problem I mentioned above, so I'd recommend just using that PR instead. I have integrated it in our fork, so feel free to switch to that (if you can't for one reason or another, I'm interested to hear what is blocking you). |
|
Thanks for looking into this and pointing me to #320! I encountered this issue while parsing real-world PyTorch source files for a downstream UAST parser: valid return statements containing starred expressions produced ERROR nodes. I kept this fix scoped to return statements to minimize grammar changes while preserving the public The main constraint on switching to the fork is downstream validation. Our UAST conversion depends on the existing CST structure, so adopting a broader set of grammar changes would require compatibility checks and a substantial regression run across our parser and analysis engine. For now, we are keeping the targeted patch while we assess #320 and the fork; this is a validation-cost constraint rather than a specific issue we have found with either. Thanks also for maintaining the fork and sharing this alternative! |
Fix parsing of valid starred expressions in return expression lists.
Previously, return values such as
return 1, *[None]andreturn 1, *([None] * 5)produced anERRORnode instead of areturn_statement.Add a return-specific expression-list rule that accepts
list_splat, while preserving the public CST node nameexpression_listand leaving the general expression-list grammar unchanged.Add corpus coverage for simple, parenthesized/binary, and multiple starred return values.
Tests:
npx tree-sitter testnpm run lintnpm testgo test ./bindings/gopython -m pytest bindings/python/testsRust binding tests were not run because
cargois unavailable in the test environment.