From 5d3b5a6b7a543546b32c3bf96215c65fc41dfd17 Mon Sep 17 00:00:00 2001 From: Bastiaan Marinus van de Weerd Date: Tue, 1 Apr 2025 21:20:17 -0300 Subject: [PATCH] Fix lambdas without params. in Python. --- .../src/stack-graphs.tsg | 10 +++++++--- .../tree-sitter-stack-graphs-python/test/lambdas.py | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) 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