Skip to content

Commit 4f60494

Browse files
committed
Python: Support assignments of the form [x,y,z] = w
Surprisingly, the new parser did not support these constructs (and the relevant test was missing this case), so on files that required the new parser we were unable to parse this construct. To fix it, we add `list_pattern` (not to be confused with `pattern_list`) as a `tree-sitter-python` node that results in a `List` node in the AST.
1 parent 89ea4b8 commit 4f60494

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

python/extractor/tests/parser/assignment.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414

1515
s, *t = u
1616

17+
[v, *w] = x
18+
1719
o,p, = q,r,

python/extractor/tsg-python/python.tsg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
[ (expression_list) (tuple) (tuple_pattern) (pattern_list) ] @tuple
2626
{ let @tuple.node = (ast-node @tuple "Tuple") }
2727

28+
(list_pattern) @list
29+
{ let @list.node = (ast-node @list "List") }
30+
2831
(call) @call { let @call.node = (ast-node @call "Call") }
2932

3033
(for_statement) @for
@@ -3436,6 +3439,9 @@
34363439
; Left hand side of an assignment such as `foo, bar = ...`
34373440
(pattern_list element: (_) @elt) @parent
34383441

3442+
; Left hand side of an assignment such as `[foo, bar] = ...`
3443+
(list_pattern element: (_) @elt) @parent
3444+
34393445
; An unadorned tuple (such as in `x = y, z`)
34403446
(expression_list element: (_) @elt) @parent
34413447

@@ -3472,6 +3478,7 @@
34723478
(tuple element: (_) @elt)
34733479
(tuple_pattern element: (_) @elt)
34743480
(pattern_list element: (_) @elt)
3481+
(list_pattern element: (_) @elt)
34753482
(expression_list element: (_) @elt)
34763483
(parenthesized_expression inner: (_) @elt)
34773484
(set element: (_) @elt)

0 commit comments

Comments
 (0)