mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Expand expressions to include parentheses in E712 (#6575)
## Summary This PR exposes our `is_expression_parenthesized` logic such that we can use it to expand expressions when autofixing to include their parenthesized ranges. This solution has a few drawbacks: (1) we need to compute parenthesized ranges in more places, which also relies on backwards lexing; and (2) we need to make use of this in any relevant fixes. However, I still think it's worth pursuing. On (1), the implementation is very contained, so IMO we can easily swap this out for a more performant solution in the future if needed. On (2), this improves correctness and fixes some bad syntax errors detected by fuzzing, which means it has value even if it's not as robust as an _actual_ `ParenthesizedExpression` node in the AST itself. Closes https://github.com/astral-sh/ruff/issues/4925. ## Test Plan `cargo test` with new cases that previously failed the fuzzer.
This commit is contained in:
parent
db1c556508
commit
1050142a58
9 changed files with 208 additions and 14 deletions
|
@ -12,6 +12,7 @@ pub mod identifier;
|
|||
pub mod imports;
|
||||
pub mod node;
|
||||
mod nodes;
|
||||
pub mod parenthesize;
|
||||
pub mod relocate;
|
||||
pub mod statement_visitor;
|
||||
pub mod stmt_if;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue