mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Add required space to C416 fix (#7204)
Closes https://github.com/astral-sh/ruff/issues/7196.
This commit is contained in:
parent
c1af1c291d
commit
fda48afc23
3 changed files with 20 additions and 1 deletions
|
@ -17,3 +17,6 @@ d = {"a": 1, "b": 2, "c": 3}
|
||||||
{k.foo: k for k in y}
|
{k.foo: k for k in y}
|
||||||
{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}
|
{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])
|
||||||
|
|
|
@ -16,6 +16,7 @@ use ruff_python_semantic::SemanticModel;
|
||||||
use ruff_source_file::Locator;
|
use ruff_source_file::Locator;
|
||||||
|
|
||||||
use crate::autofix::codemods::CodegenStylist;
|
use crate::autofix::codemods::CodegenStylist;
|
||||||
|
use crate::autofix::edits::pad;
|
||||||
use crate::cst::helpers::space;
|
use crate::cst::helpers::space;
|
||||||
use crate::rules::flake8_comprehensions::rules::ObjectType;
|
use crate::rules::flake8_comprehensions::rules::ObjectType;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -922,7 +923,7 @@ pub(crate) fn fix_unnecessary_comprehension(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
tree.codegen_stylist(stylist),
|
pad(tree.codegen_stylist(stylist), expr.range(), locator),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,4 +83,19 @@ C416.py:9:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
|
||||||
11 11 | [i for i, in z]
|
11 11 | [i for i, in z]
|
||||||
12 12 | [i for i, j in y]
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue