mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
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.
This commit is contained in:
@@ -14,4 +14,6 @@ x, y = z, w = 3, 4
|
||||
|
||||
s, *t = u
|
||||
|
||||
[v, *w] = x
|
||||
|
||||
o,p, = q,r,
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
[ (expression_list) (tuple) (tuple_pattern) (pattern_list) ] @tuple
|
||||
{ let @tuple.node = (ast-node @tuple "Tuple") }
|
||||
|
||||
(list_pattern) @list
|
||||
{ let @list.node = (ast-node @list "List") }
|
||||
|
||||
(call) @call { let @call.node = (ast-node @call "Call") }
|
||||
|
||||
(for_statement) @for
|
||||
@@ -3436,6 +3439,9 @@
|
||||
; Left hand side of an assignment such as `foo, bar = ...`
|
||||
(pattern_list element: (_) @elt) @parent
|
||||
|
||||
; Left hand side of an assignment such as `[foo, bar] = ...`
|
||||
(list_pattern element: (_) @elt) @parent
|
||||
|
||||
; An unadorned tuple (such as in `x = y, z`)
|
||||
(expression_list element: (_) @elt) @parent
|
||||
|
||||
@@ -3472,6 +3478,7 @@
|
||||
(tuple element: (_) @elt)
|
||||
(tuple_pattern element: (_) @elt)
|
||||
(pattern_list element: (_) @elt)
|
||||
(list_pattern element: (_) @elt)
|
||||
(expression_list element: (_) @elt)
|
||||
(parenthesized_expression inner: (_) @elt)
|
||||
(set element: (_) @elt)
|
||||
|
||||
Reference in New Issue
Block a user