-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix/python nested function declaration #434
fix/python nested function declaration #434
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.
Cambio
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.
Thanks! I left two suggestions, but overall this looks sensible.
@@ -794,19 +794,29 @@ inherit .parent_module | |||
edge @name.def -> @func.call | |||
|
|||
; Prevent functions defined inside of method bodies from being treated like methods | |||
; There might be a bug here as calling .self_scope after this, will not fallback to the larger scope |
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.
Do you have an idea what program might trigger this? Even if we don't fix it now, we can document it by adding test and giving it the .skip
suffix.
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.
It does not enters this branch anymore now that we only target method definitions (first level functions in classes). But I started testing stuff on tree-sitter-graph and the following stanzas reproduce this behaviour:
inherit .scope
(module) @mod {
let @mod.scope = "module"
}
(function_definition) @def {
let @def.scope = #null
}
(pass_statement) @pass {
print @pass.scope ; will be null, not module
}
def f():
pass
I don't think it is an issue anymore in stack-graphs tho (at least for python).
Maybe this is the expected behaviour but then being able to set a property to "undefined" / unset it would be useful. Let's track this in tree-sitter-graph.
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.
I'm not sure I completely understand the issue, but if this cannot be triggered by a Python program here, let's remove the comment.
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.
I'll make sure to open an issue on tree sitter graph, just to keep track of it (as it might be an issue in the future), I removed the comment.
I'm not sure those two lines are needed at all now, but I might have missed something (and it's out of this pr scope I believe)
; Prevent functions defined inside of method bodies from being treated like methods
let @body.class_self_scope = #null
let @body.class_member_attr_scope = #null
Co-authored-by: Hendrik van Antwerpen <[email protected]>
This fixes #404.
The problem was that the stanza targeted every function first param, not only methods.
As:
Was run for each function, nested function would try to create an edge to a null value:
I actually think there might be an issue with TSG itself, as
class_self_scope
andclass_member_attr_scope
are inherited, setting those to null for the function scope should fallback to a higher parent. I might investigate on this.