mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Python: Fix generator expression locations
Our logic for detecting the first and last item in a generator expression was faulty, sometimes matching comments as well. Because attributes (like `_location_start`) can only be written once, this caused `tree-sitter-graph` to get unhappy. To fix this, we now require the first item to be an `expression`, and the last one to be either a `for_in_clause` or an `if_clause`. Crucially, `comment` is neither of these, and this prevents the unfortunate overlap.
This commit is contained in:
@@ -65,3 +65,10 @@ t = tuple(x for y in z)
|
||||
d for e in f if g # comment
|
||||
# comment
|
||||
] # comment
|
||||
|
||||
# Generator expression with comments
|
||||
(# comment
|
||||
alpha # comment
|
||||
for beta in gamma # comment
|
||||
# comment
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user