diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs index ae4896f815..d09c738f16 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs @@ -978,6 +978,14 @@ pub(crate) fn fix_unnecessary_comprehension_in_call( _ => whitespace_after_arg, }; + // Remove trailing comma, if any. + // + // This relies on the fact that + // there is only one argument, + // which is already checked beforehand + // by both of this function's callers. + call.args[0].comma = None; + Ok(Fix::unsafe_edit(Edit::range_replacement( tree.codegen_stylist(stylist), expr.range(), diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C419_C419.py.snap b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C419_C419.py.snap index d1b04aebaa..529ecea6b7 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C419_C419.py.snap +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C419_C419.py.snap @@ -51,7 +51,7 @@ C419.py:4:5: C419 [*] Unnecessary list comprehension 2 2 | all([x.id for x in bar]) 3 3 | any( # first comment 4 |- [x.id for x in bar], # second comment - 4 |+ x.id for x in bar, # second comment + 4 |+ x.id for x in bar # second comment 5 5 | ) # third comment 6 6 | all( # first comment 7 7 | [x.id for x in bar], # second comment @@ -72,7 +72,7 @@ C419.py:7:5: C419 [*] Unnecessary list comprehension 5 5 | ) # third comment 6 6 | all( # first comment 7 |- [x.id for x in bar], # second comment - 7 |+ x.id for x in bar, # second comment + 7 |+ x.id for x in bar # second comment 8 8 | ) # third comment 9 9 | any({x.id for x in bar}) 10 10 |