Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 5d3b5a6

Browse files
author
Bastiaan Marinus van de Weerd
committed
Fix lambdas without params. in Python.
1 parent d0b5947 commit 5d3b5a6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ inherit .parent_module
768768
body: (_) @body
769769
) @func
770770
(lambda
771-
parameters: (_) @params
771+
parameters: (_)? @params
772772
body: (_) @body
773773
)@func
774774
] {
@@ -777,12 +777,16 @@ inherit .parent_module
777777
node drop_scope
778778

779779
edge @func.call -> return_value
780-
edge @body.before_scope -> @params.after_scope
780+
if some @params {
781+
edge @body.before_scope -> @params.after_scope
782+
}
781783
edge @body.before_scope -> drop_scope
782784
edge drop_scope -> @func.bottom
783785
attr (drop_scope) type = "drop_scopes"
784786
attr (@func.call) pop_scoped_symbol = "()"
785-
edge @params.before_scope -> JUMP_TO_SCOPE_NODE
787+
if some @params {
788+
edge @params.before_scope -> JUMP_TO_SCOPE_NODE
789+
}
786790
attr (return_value) is_exported
787791
let @func.function_returns = return_value
788792
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
sorted([1, 2, 3], key=lambda x: x)
22
# ^ defined: 1
3+
4+
y = 42
5+
6+
foo = lambda: print(y)
7+
# ^ defined: 4
8+
9+
bar = lambda daz: print(y, daz)
10+
# ^ defined: 4
11+
# ^ defined: 9

0 commit comments

Comments
 (0)