-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[syntax-errors] Async comprehension in sync comprehension #17177
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
b15f6bb
[syntax-errors] Async comprehension in sync comprehension
ntBre 336e6a3
in-line `TestContext` into SemanticSyntaxCheckerVisitor
ntBre 0835fa2
refactor some `Default` impls to make clippy happier
ntBre 3785e4b
add test_ok all-async case on 3.10 and track in_async_context
ntBre 76dd5d5
add failing linter test, this should be an error
ntBre 30a56a8
track async status for generator scopes and pass test
ntBre 7462cd6
add 3.11 test, don't reuse command, can't pass target-version twice
ntBre 04c57f0
track async context on SemanticSyntaxChecker, with checkpoint
ntBre 35f9c9c
remove apparently unnecessary checkpointing code
ntBre 50e0bc8
revert other unused context changes
ntBre f811c1a
revert unnecessary linter tests
ntBre ffcd250
tidy up and add docs
ntBre d2127e8
add more test cases, finally find a test_ok that needs checkpoints
ntBre 5b440de
restore checkpoints, convert to stack to pass test
ntBre a96ae02
restore linter tests
ntBre d49c50c
add a test case for exit_stmt and some commentary
ntBre 624f671
wire up exit methods and add test, but earlier test is failing
ntBre a21be7e
isolate the inline test that fails in the linter
ntBre bf69ef9
defer visits to function bodies
ntBre cc42a38
rename visit_{stmt,expr} to enter_{stmt,expr} and add docs
ntBre d1e1cc4
fix doc links and mention `exit_*` methods
ntBre 7f99f5f
Merge branch 'main' into brent/syn-async-comprehensions
ntBre 0f95773
return early on recent python version
ntBre 48f1e52
use the call stack instead of Vec<Checkpoint> stack
ntBre 970fe3d
Merge branch 'main' into brent/syn-async-comprehensions
ntBre 7d3b4f6
add `must_use` and some docs
ntBre 2dd610f
pass source_type to SemanticSyntaxChecker
ntBre 6db55c6
add notebook CLI test
ntBre f730e85
move non-notebook tests to ruff_linter
ntBre 83d3a70
refactor check_syntax_errors to handle notebooks, move notebook test
ntBre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
crates/ruff_python_parser/resources/inline/err/nested_async_comprehension_py310.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# parse_options: {"target-version": "3.10"} | ||
async def f(): return [[x async for x in foo(n)] for n in range(3)] # list | ||
async def g(): return [{x: 1 async for x in foo(n)} for n in range(3)] # dict | ||
async def h(): return [{x async for x in foo(n)} for n in range(3)] # set | ||
async def i(): return [([y async for y in range(1)], [z for z in range(2)]) for x in range(5)] | ||
async def j(): return [([y for y in range(1)], [z async for z in range(2)]) for x in range(5)] |
2 changes: 2 additions & 0 deletions
2
crates/ruff_python_parser/resources/inline/ok/all_async_comprehension_py310.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# parse_options: {"target-version": "3.10"} | ||
async def test(): return [[x async for x in elements(n)] async for n in range(3)] |
9 changes: 9 additions & 0 deletions
9
crates/ruff_python_parser/resources/inline/ok/nested_async_comprehension_py310.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# parse_options: {"target-version": "3.10"} | ||
# this case fails if exit_expr doesn't run | ||
async def f(): | ||
[_ for n in range(3)] | ||
[_ async for n in range(3)] | ||
# and this fails without exit_stmt | ||
async def f(): | ||
def g(): ... | ||
[_ async for n in range(3)] |
4 changes: 4 additions & 0 deletions
4
crates/ruff_python_parser/resources/inline/ok/nested_async_comprehension_py311.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# parse_options: {"target-version": "3.11"} | ||
async def f(): return [[x async for x in foo(n)] for n in range(3)] # list | ||
async def g(): return [{x: 1 async for x in foo(n)} for n in range(3)] # dict | ||
async def h(): return [{x async for x in foo(n)} for n in range(3)] # set |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's not quiet clear to me why we need those cli tests. Could some of those tests be parser tests instead? The parser tests already support
# parse_options: {"target-version": "3.7"}
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 probably don't need all of these, but the third and fourth helped to detect bugs in the
enter/exit
pairs and the deferred function body traversal. The first two are probably less valuable, if you want me to trim it down a bit.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.
It would be great if we could narrow them down and maybe document why it's important that they're CLI tests.
An alternative would be to implement them as custom tests in
ruff_linter
(that instantiate checker). Maybe there's something you can reuse from the linter test infra?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.
I adapted the
pyflakes
test runner (as suggested on Discord) and moved all of the CLI tests toruff_linter
. They're just in the top-levellinter::tests
module for now, but I'm happy to move them around if there's a better place. I also considered nesting them underrules/syntax_errors
, for example.Uh oh!
There was an error while loading. Please reload this page.
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.
I think having them in
linter::tests
is fine. They are integration tests after allThere 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.
Sounds good, thanks! I'll merge then