ruff/crates/ruff_python_parser/src
Brent Westbrook 058439d5d3
[syntax-errors] Async comprehension in sync comprehension (#17177)
Summary
--

Detect async comprehensions nested in sync comprehensions in async
functions before Python 3.11, when this was [changed].

The actual logic of this rule is very straightforward, but properly
tracking the async scopes took a bit of work. An alternative to the
current approach is to offload the `in_async_context` check into the
`SemanticSyntaxContext` trait, but that actually required much more
extensive changes to the `TestContext` and also to ruff's semantic
model, as you can see in the changes up to
31554b473507034735bd410760fde6341d54a050. This version has the benefit
of mostly centralizing the state tracking in `SemanticSyntaxChecker`,
although there was some subtlety around deferred function body traversal
that made the changes to `Checker` more intrusive too (hence the new
linter test).

The `Checkpoint` struct/system is obviously overkill for now since it's
only tracking a single `bool`, but I thought it might be more useful
later.

[changed]: https://github.com/python/cpython/issues/77527

Test Plan
--

New inline tests and a new linter integration test.
2025-04-08 12:50:52 -04:00
..
lexer Mention that `Cursor` is based on rustc's implementation. (#12109) 2024-06-30 16:53:25 +01:00
parser [syntax-errors] Invalid syntax in annotations (#17101) 2025-04-03 17:56:55 -04:00
snapshots Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
error.rs [red-knot] Add 'Format document' to playground (#17217) 2025-04-07 09:26:03 +02:00
lexer.rs Upgrade to Rust 1.86 and bump MSRV to 1.84 (#17171) 2025-04-03 15:59:44 +00:00
lib.rs [red-knot] Add basic on-hover to playground and LSP (#17057) 2025-04-04 08:13:43 +02:00
semantic_errors.rs [syntax-errors] Async comprehension in sync comprehension (#17177) 2025-04-08 12:50:52 -04:00
string.rs Upgrade to Rust 1.81 (#13265) 2024-09-06 15:09:09 +02:00
token.rs [syntax-errors] PEP 701 f-strings before Python 3.12 (#16543) 2025-03-18 11:12:15 -04:00
token_set.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
token_source.rs [syntax-errors] PEP 701 f-strings before Python 3.12 (#16543) 2025-03-18 11:12:15 -04:00
typing.rs Rename `ExprStringLiteral::as_unconcatenated_string()` to `ExprStringLiteral::as_single_part_string()` (#16253) 2025-02-19 16:06:57 +00:00