mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-17 03:18:38 +00:00
Merge 376ebd63e4 into 3065f8dbbc
This commit is contained in:
commit
9a7941a91e
1 changed files with 18 additions and 7 deletions
|
|
@ -111,13 +111,24 @@ pub(crate) fn for_loop_set_mutations(checker: &Checker, for_stmt: &StmtFor) {
|
|||
parenthesize_loop_iter_if_necessary(for_stmt, checker, IterLocation::Call),
|
||||
)
|
||||
}
|
||||
(for_target, arg) => format!(
|
||||
"{}.{batch_method_name}({} for {} in {})",
|
||||
set.id,
|
||||
locator.slice(arg),
|
||||
locator.slice(for_target),
|
||||
parenthesize_loop_iter_if_necessary(for_stmt, checker, IterLocation::Comprehension),
|
||||
),
|
||||
(for_target, arg) => {
|
||||
// Parenthesize an unparenthesized generator expression argument to preserve semantics,
|
||||
// e.g. `s.add(c for c in x)` -> `s.update((c for c in x) for x in ...)`.
|
||||
let arg_text = match arg {
|
||||
Expr::Generator(generator) if !generator.parenthesized => {
|
||||
format!("({})", locator.slice(arg))
|
||||
}
|
||||
_ => locator.slice(arg).to_string(),
|
||||
};
|
||||
|
||||
format!(
|
||||
"{}.{batch_method_name}({} for {} in {})",
|
||||
set.id,
|
||||
arg_text,
|
||||
locator.slice(for_target),
|
||||
parenthesize_loop_iter_if_necessary(for_stmt, checker, IterLocation::Comprehension),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
let applicability = if checker.comment_ranges().intersects(for_stmt.range) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue