Skip to content

Commit ef60b73

Browse files
committed
Python: Fix parenthesized tuple parser bug
We were writing the `parenthesised` attribute twice on tuples, once because of the explicit parenthetisation, and once because all non-empty tuples are parenthesised. This made `tree-sitter-graph` unhappy. To fix this, we now explicitly check whether a tuple is already parenthesised, and do nothing if that is the case.
1 parent b4ecc79 commit ef60b73

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

python/extractor/tests/parser/collections.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@
3535
x, y,
3636
#comment
3737
)
38+
39+
((z,))

python/extractor/tsg-python/python.tsg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3485,5 +3485,9 @@
34853485

34863486
[(tuple element: (_)) (tuple_pattern)] @tup
34873487
{
3488-
attr (@tup.node) parenthesised = #true
3488+
; In order to avoid writing to the `parenthesised` attribute twice, we only set it here
3489+
; if the surrounding expression is not a `parenthesized_expression`.
3490+
if (not (instance-of (get-parent @tup) "parenthesized_expression")) {
3491+
attr (@tup.node) parenthesised = #true
3492+
}
34893493
}

0 commit comments

Comments
 (0)