diff --git a/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg b/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg index 5fb407ae8..d8e673b4e 100644 --- a/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg +++ b/languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg @@ -768,7 +768,7 @@ inherit .parent_module body: (_) @body ) @func (lambda - parameters: (_) @params + parameters: (_)? @params body: (_) @body )@func ] { @@ -777,12 +777,16 @@ inherit .parent_module node drop_scope edge @func.call -> return_value - edge @body.before_scope -> @params.after_scope + if some @params { + edge @body.before_scope -> @params.after_scope + } edge @body.before_scope -> drop_scope edge drop_scope -> @func.bottom attr (drop_scope) type = "drop_scopes" attr (@func.call) pop_scoped_symbol = "()" - edge @params.before_scope -> JUMP_TO_SCOPE_NODE + if some @params { + edge @params.before_scope -> JUMP_TO_SCOPE_NODE + } attr (return_value) is_exported let @func.function_returns = return_value } diff --git a/languages/tree-sitter-stack-graphs-python/test/lambdas.py b/languages/tree-sitter-stack-graphs-python/test/lambdas.py index 9812df4de..a3d294b56 100644 --- a/languages/tree-sitter-stack-graphs-python/test/lambdas.py +++ b/languages/tree-sitter-stack-graphs-python/test/lambdas.py @@ -1,2 +1,11 @@ sorted([1, 2, 3], key=lambda x: x) # ^ defined: 1 + +y = 42 + +foo = lambda: print(y) +# ^ defined: 4 + +bar = lambda daz: print(y, daz) +# ^ defined: 4 +# ^ defined: 9