-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Python: Even more parser fixes #17873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1e51703
ac87868
e710c0a
b4ecc79
ef60b73
5d6600e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
async def foo(): | ||
await bar() + await baz() | ||
|
||
async with foo() as bar, baz() as quux: | ||
pass | ||
|
||
async for spam in eggs: | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ | |
x, y, | ||
#comment | ||
) | ||
|
||
((z,)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,12 @@ | |
b'\xc5\xe5' | ||
if 35: | ||
f"{x=}" | ||
if 36: | ||
r"a\"a" | ||
if 37: | ||
r'a\'a' | ||
if 38: | ||
r'a\\' | ||
if 39: | ||
r'a\ | ||
' | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,7 +404,7 @@ | |
|
||
;;; GeneratorExp | ||
|
||
(generator_expression . "(" . (comment)* . (_) @start (_) @end . (comment)* . ")" .) @generatorexp | ||
(generator_expression . "(" . (comment)* . (expression) @start [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @generatorexp | ||
{ | ||
attr (@generatorexp.node) _location_start = (location-start @start) | ||
attr (@generatorexp.node) _location_end = (location-end @end) | ||
|
@@ -416,13 +416,13 @@ | |
attr (@if.node) _location_end = (location-end @expr) | ||
} | ||
|
||
(generator_expression . "(" . (comment)* . (_) @start (for_in_clause) @child (_) @end . (comment)* . ")" .) @genexpr | ||
(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @child [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @genexpr | ||
{ | ||
attr (@child.node) _location_start = (location-start @start) | ||
attr (@child.node) _location_end = (location-end @end) | ||
} | ||
|
||
(generator_expression . "(" . (comment)* . (_) @start (for_in_clause) @end . (comment)* . ")" .) @genexpr | ||
(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @end . (comment)* . ")" .) @genexpr | ||
{ | ||
attr (@end.node) _location_start = (location-start @start) | ||
attr (@end.node) _location_end = (location-end @end) | ||
|
@@ -863,7 +863,7 @@ | |
; information for the entire generator expression (yes, it is a wide parameter!) and so we must recreate the logic for | ||
; setting this location information correctly. | ||
|
||
(generator_expression . "(" . (comment)* . (_) @start (_) @end . (comment)* . ")" .) @genexpr | ||
(generator_expression . "(" . (comment)* . (expression) @start [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @genexpr | ||
{ | ||
; Synthesize the `genexpr` function | ||
let @genexpr.fun = (ast-node @genexpr "Function") | ||
|
@@ -2650,6 +2650,14 @@ | |
let @with.first = @first.node | ||
} | ||
|
||
; Async status | ||
; NOTE: We only set the `is_async` field on the _first_ clause of the `with` statement, | ||
; as this is the behaviour of the old parser. | ||
(with_statement "async" "with" @with_keyword (with_clause . (with_item) @with)) | ||
{ | ||
attr (@with.node) is_async = #true | ||
} | ||
|
||
(with_item | ||
value: (_) @value | ||
) @with | ||
|
@@ -3253,6 +3261,16 @@ | |
} | ||
} | ||
|
||
; Async status | ||
(function_definition "async" "def" @def_keyword) @funcdef | ||
{ | ||
let start = (location-start @def_keyword) | ||
attr (@funcdef.function) is_async = #true | ||
attr (@funcdef.node) _location_start = start | ||
attr (@funcdef.function) _location_start = start | ||
attr (@funcdef.funcexpr) _location_start = start | ||
Comment on lines
+3269
to
+3271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were these also never set for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. (This is something I hope we can get rid of in the future, as I don't really have a good justification for it other than "it's how we've always done it.) |
||
} | ||
|
||
;;; Decorators | ||
|
||
(decorated_definition | ||
|
@@ -3467,5 +3485,9 @@ | |
|
||
[(tuple element: (_)) (tuple_pattern)] @tup | ||
{ | ||
attr (@tup.node) parenthesised = #true | ||
; In order to avoid writing to the `parenthesised` attribute twice, we only set it here | ||
; if the surrounding expression is not a `parenthesized_expression`. | ||
if (not (instance-of (get-parent @tup) "parenthesized_expression")) { | ||
attr (@tup.node) parenthesised = #true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do/should we test both the
\n
\rn
cases?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but it's somewhat fiddly as we normalise all line endings when committing. In this case, I think the benefits would be marginal at best.