-
Notifications
You must be signed in to change notification settings - Fork 156
Fix multiple Python TSG grammar scoping errors #498
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes multiple Python Tree-sitter Stack Graphs (TSG) grammar scoping errors by improving scope tracking, symbol resolution, and support for advanced Python features. The changes address issue #497 and enhance the handling of typed splat parameters, subclass initialization with keyword parameters, and lambda expressions.
Key changes:
- Improved lambda function scoping with separate handlers for lambdas with and without parameters
- Enhanced parameter pattern matching to support typed splat parameters (*args and **kwargs)
- Fixed assignment expression handling and superclass argument processing
- Added comprehensive test cases for the new functionality
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/stack-graphs.tsg |
Core grammar fixes including lambda scoping, parameter patterns, and assignment handling |
test/typed_splat_params.py |
Test case for typed splat parameter resolution |
test/superclasses.py |
Test case for subclass initialization with keyword parameters |
test/lambdas.py |
Extended test cases for lambda scope resolution |
test/assignments.py |
Test case for assignment expression handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| (lambda | ||
| body: (_) @body | ||
| ) @lam { | ||
| node @lam.call | ||
| node return_value | ||
| node @body.after_scope | ||
|
|
||
| edge @lam.call -> return_value | ||
| edge @body.before_scope -> @body.after_scope | ||
| edge @body.after_scope -> @lam.bottom | ||
| attr (@lam.call) pop_scoped_symbol = "()" | ||
| attr (return_value) is_exported | ||
| let @lam.function_returns = return_value | ||
| } | ||
|
|
||
| (lambda | ||
| parameters: (_) @params | ||
| body: (_) @body | ||
| ) { | ||
| edge @body.before_scope -> @params.after_scope | ||
| edge @params.before_scope -> JUMP_TO_SCOPE_NODE | ||
| edge @params.after_scope -> @body.after_scope | ||
| } |
Copilot
AI
Sep 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The lambda handling is split into two separate rules that could lead to duplication. Consider consolidating the common scope setup logic or adding a comment explaining why this separation is necessary for the grammar to work correctly.
| (parameter/typed_parameter | ||
| . (_) @name) @param | ||
| . (identifier) @name) @param | ||
| (parameter/typed_parameter | ||
| . (list_splat_pattern | ||
| (_) @name)) @param | ||
| (parameter/typed_parameter | ||
| . (dictionary_splat_pattern | ||
| (_) @name)) @param |
Copilot
AI
Sep 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The parameter pattern matching rules are repetitive. Consider using a more concise pattern that captures all these cases, or add comments explaining the specific requirements for each pattern type.
|
The github/stack-graphs repository is no longer being maintained. As per #502, I'm closing all issues and pull requests before archiving the repository. |
Address #497
The changes enhance scope tracking, symbol resolution, and support for Python features such as typed splat parameters, subclass initialization with keyword parameters and lambdas.