Skip to content

Commit

Permalink
Add required space to C416 fix (#7204)
Browse files Browse the repository at this point in the history
Closes #7196.
  • Loading branch information
charliermarsh authored and zanieb committed Sep 6, 2023
1 parent 209a0ad commit 8c4c618
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
{k.foo: k for k in y}
{k["foo"]: k for k in y}
{k: v if v else None for k, v in y}

# Regression test for: https://github.com/astral-sh/ruff/issues/7196
any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in[t for t in SymbolType])
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/flake8_comprehensions/fixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ruff_python_semantic::SemanticModel;
use ruff_source_file::Locator;

use crate::autofix::codemods::CodegenStylist;
use crate::autofix::edits::pad;
use crate::cst::helpers::space;
use crate::rules::flake8_comprehensions::rules::ObjectType;
use crate::{
Expand Down Expand Up @@ -922,7 +923,7 @@ pub(crate) fn fix_unnecessary_comprehension(
}

Ok(Edit::range_replacement(
tree.codegen_stylist(stylist),
pad(tree.codegen_stylist(stylist), expr.range(), locator),
expr.range(),
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,19 @@ C416.py:9:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
11 11 | [i for i, in z]
12 12 | [i for i, j in y]

C416.py:22:70: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
|
21 | # Regression test for: https://github.com/astral-sh/ruff/issues/7196
22 | any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in[t for t in SymbolType])
| ^^^^^^^^^^^^^^^^^^^^^^^ C416
|
= help: Rewrite using `list()`

Suggested fix
19 19 | {k: v if v else None for k, v in y}
20 20 |
21 21 | # Regression test for: https://github.com/astral-sh/ruff/issues/7196
22 |-any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in[t for t in SymbolType])
22 |+any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in list(SymbolType))


0 comments on commit 8c4c618

Please sign in to comment.