Refactor applicability to use safe and unsafe

This commit is contained in:
Zanie 2023-10-04 14:04:08 -05:00
parent 59c00b5298
commit c5ae2f1b9d
399 changed files with 2013 additions and 2001 deletions

View File

@ -175,7 +175,9 @@ import os
},
"filename": "-",
"fix": {
"applicability": "Automatic",
"applicability": {
"automatic": "safe"
},
"edits": [
{
"content": "",

View File

@ -24,7 +24,9 @@ exit_code: 1
},
"filename": "/path/to/F401.py",
"fix": {
"applicability": "Automatic",
"applicability": {
"automatic": "safe"
},
"edits": [
{
"content": "",

View File

@ -5,27 +5,31 @@ use ruff_text_size::{Ranged, TextSize};
use crate::edit::Edit;
/// Indicates confidence in the correctness of a suggested fix.
#[derive(Default, Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
/// Indicates if a fix can be applied.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum Applicability {
/// The fix is definitely what the user intended, or maintains the exact meaning of the code.
/// This fix should be automatically applied.
Automatic,
/// The fix can be applied programmatically.
/// The fix is likely to be correct and the resulting code will have valid syntax.
Automatic(Safety),
/// The fix may be what the user intended, but it is uncertain.
/// The fix should result in valid code if it is applied.
/// The fix can be applied with user opt-in.
Suggested,
/// The fix has a good chance of being incorrect or the code be incomplete.
/// The fix may result in invalid code if it is applied.
/// The fix should only be manually applied by the user.
/// The fix is likely to be incorrect or the resulting code may have invalid syntax.
Manual,
}
/// The applicability of the fix is unknown.
#[default]
Unspecified,
/// Indicates the safety of applying a fix.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[serde(rename_all = "lowercase")]
pub enum Safety {
/// The fix is definitely what the user intended, or it maintains the exact meaning of the code.
/// This fix can be automatically applied.
Safe,
/// The fix may be what the user intended, but it is uncertain.
/// The fix can be applied with user opt-in.
Unsafe,
}
/// Indicates the level of isolation required to apply a fix.
@ -52,66 +56,42 @@ pub struct Fix {
}
impl Fix {
/// Create a new [`Fix`] with an unspecified applicability from an [`Edit`] element.
#[deprecated(
note = "Use `Fix::automatic`, `Fix::suggested`, or `Fix::manual` instead to specify an applicability."
)]
pub fn unspecified(edit: Edit) -> Self {
/// Create a new [`Fix`] with [safe applicability](Applicability::Automatic(Safety::Safe)) from an [`Edit`] element.
pub fn automatic_safe(edit: Edit) -> Self {
Self {
edits: vec![edit],
applicability: Applicability::Unspecified,
applicability: Applicability::Automatic(Safety::Safe),
isolation_level: IsolationLevel::default(),
}
}
/// Create a new [`Fix`] with an unspecified applicability from multiple [`Edit`] elements.
#[deprecated(
note = "Use `Fix::automatic_edits`, `Fix::suggested_edits`, or `Fix::manual_edits` instead to specify an applicability."
)]
pub fn unspecified_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
Self {
edits: std::iter::once(edit).chain(rest).collect(),
applicability: Applicability::Unspecified,
isolation_level: IsolationLevel::default(),
}
}
/// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from an [`Edit`] element.
pub fn automatic(edit: Edit) -> Self {
Self {
edits: vec![edit],
applicability: Applicability::Automatic,
isolation_level: IsolationLevel::default(),
}
}
/// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from multiple [`Edit`] elements.
pub fn automatic_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
/// Create a new [`Fix`] with [safe applicability](Applicability::Automatic(Safety::Safe)) from multiple [`Edit`] elements.
pub fn automatic_safe_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
let mut edits: Vec<Edit> = std::iter::once(edit).chain(rest).collect();
edits.sort_by_key(|edit| (edit.start(), edit.end()));
Self {
edits,
applicability: Applicability::Automatic,
applicability: Applicability::Automatic(Safety::Safe),
isolation_level: IsolationLevel::default(),
}
}
/// Create a new [`Fix`] with [suggested applicability](Applicability::Suggested) from an [`Edit`] element.
pub fn suggested(edit: Edit) -> Self {
/// Create a new [`Fix`] with [unsafe applicability](Applicable::Automatic(Safety::Unsafe)) from an [`Edit`] element.
pub fn automatic_unsafe(edit: Edit) -> Self {
Self {
edits: vec![edit],
applicability: Applicability::Suggested,
applicability: Applicability::Automatic(Safety::Unsafe),
isolation_level: IsolationLevel::default(),
}
}
/// Create a new [`Fix`] with [suggested applicability](Applicability::Suggested) from multiple [`Edit`] elements.
pub fn suggested_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
/// Create a new [`Fix`] with [unsafe applicability](Applicability::Automatic(Safety::Unsafe)) from multiple [`Edit`] elements.
pub fn automatic_unsafe_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
let mut edits: Vec<Edit> = std::iter::once(edit).chain(rest).collect();
edits.sort_by_key(|edit| (edit.start(), edit.end()));
Self {
edits,
applicability: Applicability::Suggested,
applicability: Applicability::Automatic(Safety::Unsafe),
isolation_level: IsolationLevel::default(),
}
}

View File

@ -1,6 +1,6 @@
pub use diagnostic::{Diagnostic, DiagnosticKind};
pub use edit::Edit;
pub use fix::{Applicability, Fix, IsolationLevel};
pub use fix::{Applicability, Fix, IsolationLevel, Safety};
pub use source_map::{SourceMap, SourceMarker};
pub use violation::{AlwaysFixableViolation, FixAvailability, Violation};

View File

@ -38,7 +38,7 @@ pub(crate) fn bindings(checker: &mut Checker) {
binding,
checker.locator,
)
.map(Fix::automatic)
.map(Fix::automatic_safe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -110,8 +110,10 @@ pub(crate) fn check_noqa(
let mut diagnostic =
Diagnostic::new(UnusedNOQA { codes: None }, directive.range());
if settings.rules.should_fix(diagnostic.kind.rule()) {
diagnostic
.set_fix(Fix::suggested(delete_noqa(directive.range(), locator)));
diagnostic.set_fix(Fix::automatic_unsafe(delete_noqa(
directive.range(),
locator,
)));
}
diagnostics.push(diagnostic);
}
@ -175,12 +177,12 @@ pub(crate) fn check_noqa(
);
if settings.rules.should_fix(diagnostic.kind.rule()) {
if valid_codes.is_empty() {
diagnostic.set_fix(Fix::suggested(delete_noqa(
diagnostic.set_fix(Fix::automatic_unsafe(delete_noqa(
directive.range(),
locator,
)));
} else {
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
format!("# noqa: {}", valid_codes.join(", ")),
directive.range(),
)));

View File

@ -151,7 +151,7 @@ mod tests {
// The choice of rule here is arbitrary.
kind: MissingNewlineAtEndOfFile.into(),
range: edit.range(),
fix: Some(Fix::unspecified(edit)),
fix: Some(Fix::automatic_safe(edit)),
parent: None,
})
.collect()

View File

@ -6,7 +6,7 @@ use colored::{Color, ColoredString, Colorize, Styles};
use ruff_text_size::{Ranged, TextRange, TextSize};
use similar::{ChangeTag, TextDiff};
use ruff_diagnostics::{Applicability, Fix};
use ruff_diagnostics::{Applicability, Fix, Safety};
use ruff_source_file::{OneIndexed, SourceFile};
use crate::message::Message;
@ -52,10 +52,12 @@ impl Display for Diff<'_> {
let diff = TextDiff::from_lines(self.source_code.source_text(), &output);
let message = match self.fix.applicability() {
Applicability::Automatic => "Fix",
Applicability::Suggested => "Suggested fix",
Applicability::Manual => "Possible fix",
Applicability::Unspecified => "Suggested fix", /* For backwards compatibility, unspecified fixes are 'suggested' */
// TODO(zanieb): Adjust this messaging once it's user-facing
Applicability::Automatic(safety) => match safety {
Safety::Safe => "Fix",
Safety::Unsafe => "Unsafe fix",
},
Applicability::Manual => "Manual fix",
};
writeln!(f, " {}", message.blue())?;

View File

@ -178,7 +178,7 @@ def fibonacci(n):
},
TextRange::new(TextSize::from(7), TextSize::from(9)),
)
.with_fix(Fix::suggested(Edit::range_deletion(TextRange::new(
.with_fix(Fix::automatic_unsafe(Edit::range_deletion(TextRange::new(
TextSize::from(0),
TextSize::from(10),
))));
@ -193,7 +193,7 @@ def fibonacci(n):
},
TextRange::new(TextSize::from(94), TextSize::from(95)),
)
.with_fix(Fix::suggested(Edit::deletion(
.with_fix(Fix::automatic_unsafe(Edit::deletion(
TextSize::from(94),
TextSize::from(99),
)));

View File

@ -11,7 +11,9 @@ expression: content
},
"filename": "fib.py",
"fix": {
"applicability": "Suggested",
"applicability": {
"automatic": "unsafe"
},
"edits": [
{
"content": "",
@ -43,7 +45,9 @@ expression: content
},
"filename": "fib.py",
"fix": {
"applicability": "Suggested",
"applicability": {
"automatic": "unsafe"
},
"edits": [
{
"content": "",

View File

@ -2,7 +2,7 @@
source: crates/ruff_linter/src/message/json_lines.rs
expression: content
---
{"code":"F401","end_location":{"column":10,"row":1},"filename":"fib.py","fix":{"applicability":"Suggested","edits":[{"content":"","end_location":{"column":1,"row":2},"location":{"column":1,"row":1}}],"message":"Remove unused import: `os`"},"location":{"column":8,"row":1},"message":"`os` imported but unused","noqa_row":1,"url":"https://docs.astral.sh/ruff/rules/unused-import"}
{"code":"F841","end_location":{"column":6,"row":6},"filename":"fib.py","fix":{"applicability":"Suggested","edits":[{"content":"","end_location":{"column":10,"row":6},"location":{"column":5,"row":6}}],"message":"Remove assignment to unused variable `x`"},"location":{"column":5,"row":6},"message":"Local variable `x` is assigned to but never used","noqa_row":6,"url":"https://docs.astral.sh/ruff/rules/unused-variable"}
{"code":"F401","end_location":{"column":10,"row":1},"filename":"fib.py","fix":{"applicability":{"automatic":"unsafe"},"edits":[{"content":"","end_location":{"column":1,"row":2},"location":{"column":1,"row":1}}],"message":"Remove unused import: `os`"},"location":{"column":8,"row":1},"message":"`os` imported but unused","noqa_row":1,"url":"https://docs.astral.sh/ruff/rules/unused-import"}
{"code":"F841","end_location":{"column":6,"row":6},"filename":"fib.py","fix":{"applicability":{"automatic":"unsafe"},"edits":[{"content":"","end_location":{"column":10,"row":6},"location":{"column":5,"row":6}}],"message":"Remove assignment to unused variable `x`"},"location":{"column":5,"row":6},"message":"Local variable `x` is assigned to but never used","noqa_row":6,"url":"https://docs.astral.sh/ruff/rules/unused-variable"}
{"code":"F821","end_location":{"column":5,"row":1},"filename":"undef.py","fix":null,"location":{"column":4,"row":1},"message":"Undefined name `a`","noqa_row":1,"url":"https://docs.astral.sh/ruff/rules/undefined-name"}

View File

@ -10,7 +10,7 @@ ERA001.py:1:1: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
1 |-#import os
2 1 | # from foo import junk
3 2 | #a = 3
@ -26,7 +26,7 @@ ERA001.py:2:1: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
1 1 | #import os
2 |-# from foo import junk
3 2 | #a = 3
@ -44,7 +44,7 @@ ERA001.py:3:1: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
1 1 | #import os
2 2 | # from foo import junk
3 |-#a = 3
@ -63,7 +63,7 @@ ERA001.py:5:1: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
2 2 | # from foo import junk
3 3 | #a = 3
4 4 | a = 4
@ -82,7 +82,7 @@ ERA001.py:13:5: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
10 10 |
11 11 | # This is a real comment.
12 12 | # # This is a (nested) comment.
@ -100,7 +100,7 @@ ERA001.py:21:5: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
18 18 |
19 19 | class A():
20 20 | pass
@ -120,7 +120,7 @@ ERA001.py:26:5: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
23 23 |
24 24 | dictionary = {
25 25 | # "key1": 123, # noqa: ERA001
@ -139,7 +139,7 @@ ERA001.py:27:5: ERA001 [*] Found commented-out code
|
= help: Remove commented-out code
Possible fix
Manual fix
24 24 | dictionary = {
25 25 | # "key1": 123, # noqa: ERA001
26 26 | # "key2": 456,

View File

@ -703,7 +703,7 @@ pub(crate) fn definition(
function.identifier(),
);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::suggested(Edit::insertion(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::insertion(
" -> None".to_string(),
function.parameters.range().end(),
)));
@ -721,7 +721,7 @@ pub(crate) fn definition(
);
if checker.patch(diagnostic.kind.rule()) {
if let Some(return_type) = simple_magic_return_type(name) {
diagnostic.set_fix(Fix::suggested(Edit::insertion(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::insertion(
format!(" -> {return_type}"),
function.parameters.range().end(),
)));

View File

@ -252,7 +252,7 @@ annotation_presence.py:159:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
156 156 |
157 157 | class Foo:
158 158 | @decorator()
@ -272,7 +272,7 @@ annotation_presence.py:165:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
162 162 |
163 163 | # Regression test for: https://github.com/astral-sh/ruff/issues/7711
164 164 | class Class:

View File

@ -11,7 +11,7 @@ mypy_init_return.py:5:9: ANN204 [*] Missing return type annotation for special m
|
= help: Add `None` return type
Suggested fix
Unsafe fix
2 2 |
3 3 | # Error
4 4 | class Foo:
@ -31,7 +31,7 @@ mypy_init_return.py:11:9: ANN204 [*] Missing return type annotation for special
|
= help: Add `None` return type
Suggested fix
Unsafe fix
8 8 |
9 9 | # Error
10 10 | class Foo:
@ -59,7 +59,7 @@ mypy_init_return.py:47:9: ANN204 [*] Missing return type annotation for special
|
= help: Add `None` return type
Suggested fix
Unsafe fix
44 44 | # Error used to be ok for a moment since the mere presence
45 45 | # of a vararg falsely indicated that the function has a typed argument.
46 46 | class Foo:

View File

@ -10,7 +10,7 @@ simple_magic_methods.py:2:9: ANN204 [*] Missing return type annotation for speci
|
= help: Add `None` return type
Suggested fix
Unsafe fix
1 1 | class Foo:
2 |- def __str__(self):
2 |+ def __str__(self) -> str:
@ -28,7 +28,7 @@ simple_magic_methods.py:5:9: ANN204 [*] Missing return type annotation for speci
|
= help: Add `None` return type
Suggested fix
Unsafe fix
2 2 | def __str__(self):
3 3 | ...
4 4 |
@ -48,7 +48,7 @@ simple_magic_methods.py:8:9: ANN204 [*] Missing return type annotation for speci
|
= help: Add `None` return type
Suggested fix
Unsafe fix
5 5 | def __repr__(self):
6 6 | ...
7 7 |
@ -68,7 +68,7 @@ simple_magic_methods.py:11:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
8 8 | def __len__(self):
9 9 | ...
10 10 |
@ -88,7 +88,7 @@ simple_magic_methods.py:14:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
11 11 | def __length_hint__(self):
12 12 | ...
13 13 |
@ -108,7 +108,7 @@ simple_magic_methods.py:17:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
14 14 | def __init__(self):
15 15 | ...
16 16 |
@ -128,7 +128,7 @@ simple_magic_methods.py:20:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
17 17 | def __del__(self):
18 18 | ...
19 19 |
@ -148,7 +148,7 @@ simple_magic_methods.py:23:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
20 20 | def __bool__(self):
21 21 | ...
22 22 |
@ -168,7 +168,7 @@ simple_magic_methods.py:26:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
23 23 | def __bytes__(self):
24 24 | ...
25 25 |
@ -188,7 +188,7 @@ simple_magic_methods.py:29:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
26 26 | def __format__(self, format_spec):
27 27 | ...
28 28 |
@ -208,7 +208,7 @@ simple_magic_methods.py:32:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
29 29 | def __contains__(self, item):
30 30 | ...
31 31 |
@ -228,7 +228,7 @@ simple_magic_methods.py:35:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
32 32 | def __complex__(self):
33 33 | ...
34 34 |
@ -248,7 +248,7 @@ simple_magic_methods.py:38:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
35 35 | def __int__(self):
36 36 | ...
37 37 |
@ -268,7 +268,7 @@ simple_magic_methods.py:41:9: ANN204 [*] Missing return type annotation for spec
|
= help: Add `None` return type
Suggested fix
Unsafe fix
38 38 | def __float__(self):
39 39 | ...
40 40 |

View File

@ -76,7 +76,7 @@ pub(crate) fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg:
let mut diagnostic = Diagnostic::new(AssertFalse, test.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
checker.generator().stmt(&assertion_error(msg)),
stmt.range(),
)));

View File

@ -147,7 +147,7 @@ fn duplicate_handler_exceptions<'a>(
expr.range(),
);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
// Single exceptions don't require parentheses, but since we're _removing_
// parentheses, insert whitespace as needed.
if let [elt] = unique_elts.as_slice() {

View File

@ -86,7 +86,7 @@ pub(crate) fn getattr_with_constant(
let mut diagnostic = Diagnostic::new(GetAttrWithConstant, expr.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
pad(
if matches!(
obj,

View File

@ -85,7 +85,7 @@ pub(crate) fn redundant_tuple_in_exception_handler(
// ```
// Otherwise, the output will be invalid syntax, since we're removing a set of
// parentheses.
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
pad(
checker.generator().expr(elt),
type_.range(),

View File

@ -109,7 +109,7 @@ pub(crate) fn setattr_with_constant(
if expr == child.as_ref() {
let mut diagnostic = Diagnostic::new(SetAttrWithConstant, expr.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
assignment(obj, name, value, checker.generator()),
expr.range(),
)));

View File

@ -83,7 +83,7 @@ pub(crate) fn unreliable_callable_check(
if checker.patch(diagnostic.kind.rule()) {
if id == "hasattr" {
if checker.semantic().is_builtin("callable") {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
format!("callable({})", checker.locator().slice(obj)),
expr.range(),
)));

View File

@ -168,7 +168,7 @@ pub(crate) fn unused_loop_control_variable(checker: &mut Checker, stmt_for: &ast
.filter(|binding| binding.start() >= expr.start())
.all(|binding| !binding.is_used())
{
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
rename,
expr.range(),
)));

View File

@ -12,7 +12,7 @@ B006_1.py:3:22: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
1 1 | # Docstring followed by a newline
2 2 |
3 |-def foobar(foor, bar={}):

View File

@ -12,7 +12,7 @@ B006_2.py:4:22: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
1 1 | # Docstring followed by whitespace with no newline
2 2 | # Regression test for https://github.com/astral-sh/ruff/issues/7155
3 3 |

View File

@ -10,7 +10,7 @@ B006_3.py:4:22: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
1 1 | # Docstring with no newline
2 2 |
3 3 |

View File

@ -10,7 +10,7 @@ B006_4.py:7:26: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
4 4 |
5 5 |
6 6 | class FormFeedIndent:

View File

@ -9,7 +9,7 @@ B006_5.py:5:49: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
2 2 | # https://github.com/astral-sh/ruff/issues/7616
3 3 |
4 4 |
@ -30,7 +30,7 @@ B006_5.py:9:61: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
6 6 | import os
7 7 |
8 8 |
@ -53,7 +53,7 @@ B006_5.py:15:50: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
12 12 | return 2
13 13 |
14 14 |
@ -76,7 +76,7 @@ B006_5.py:21:54: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
18 18 | import itertools
19 19 |
20 20 |
@ -98,7 +98,7 @@ B006_5.py:25:55: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
22 22 | from os import path
23 23 |
24 24 |
@ -121,7 +121,7 @@ B006_5.py:30:66: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
27 27 | from sys import version_info
28 28 |
29 29 |
@ -144,7 +144,7 @@ B006_5.py:35:59: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
32 32 | from sys import version_info
33 33 |
34 34 |
@ -167,7 +167,7 @@ B006_5.py:40:49: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
37 37 | import os
38 38 |
39 39 |
@ -190,7 +190,7 @@ B006_5.py:45:49: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
42 42 | import os; import sys
43 43 |
44 44 |
@ -212,7 +212,7 @@ B006_5.py:50:49: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
47 47 | import os; import sys; x = 1
48 48 |
49 49 |
@ -234,7 +234,7 @@ B006_5.py:55:49: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
52 52 | import os; import sys
53 53 |
54 54 |
@ -255,7 +255,7 @@ B006_5.py:59:49: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
56 56 | import os; import sys
57 57 |
58 58 |
@ -275,7 +275,7 @@ B006_5.py:63:49: B006 [*] Do not use mutable data structures for argument defaul
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
60 60 | import os; import sys; x = 1
61 61 |
62 62 |

View File

@ -11,7 +11,7 @@ B006_6.py:4:22: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
1 1 | # Import followed by whitespace with no newline
2 2 | # Same as B006_2.py, but import instead of docstring
3 3 |

View File

@ -11,7 +11,7 @@ B006_7.py:4:22: B006 [*] Do not use mutable data structures for argument default
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
1 1 | # Import with no newline
2 2 | # Same as B006_3.py, but import instead of docstring
3 3 |

View File

@ -9,7 +9,7 @@ B006_B008.py:63:25: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
60 60 | # Flag mutable literals/comprehensions
61 61 |
62 62 |
@ -29,7 +29,7 @@ B006_B008.py:67:30: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
64 64 | ...
65 65 |
66 66 |
@ -51,7 +51,7 @@ B006_B008.py:73:52: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
70 70 |
71 71 | class Foo:
72 72 | @staticmethod
@ -74,7 +74,7 @@ B006_B008.py:77:31: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
74 74 | pass
75 75 |
76 76 |
@ -105,7 +105,7 @@ B006_B008.py:85:20: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
82 82 | def single_line_func_wrong(value = {}): ...
83 83 |
84 84 |
@ -125,7 +125,7 @@ B006_B008.py:89:20: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
86 86 | ...
87 87 |
88 88 |
@ -145,7 +145,7 @@ B006_B008.py:93:32: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
90 90 | ...
91 91 |
92 92 |
@ -165,7 +165,7 @@ B006_B008.py:97:26: B006 [*] Do not use mutable data structures for argument def
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
94 94 | ...
95 95 |
96 96 |
@ -186,7 +186,7 @@ B006_B008.py:102:46: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
99 99 |
100 100 |
101 101 | # N.B. we're also flagging the function call in the comprehension
@ -206,7 +206,7 @@ B006_B008.py:106:46: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
103 103 | pass
104 104 |
105 105 |
@ -226,7 +226,7 @@ B006_B008.py:110:45: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
107 107 | pass
108 108 |
109 109 |
@ -246,7 +246,7 @@ B006_B008.py:114:33: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
111 111 | pass
112 112 |
113 113 |
@ -268,7 +268,7 @@ B006_B008.py:239:20: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
236 236 |
237 237 | # B006 and B008
238 238 | # We should handle arbitrary nesting of these B008.
@ -290,7 +290,7 @@ B006_B008.py:276:27: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
273 273 |
274 274 |
275 275 | def mutable_annotations(
@ -317,7 +317,7 @@ B006_B008.py:277:35: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
274 274 |
275 275 | def mutable_annotations(
276 276 | a: list[int] | None = [],
@ -343,7 +343,7 @@ B006_B008.py:278:62: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
275 275 | def mutable_annotations(
276 276 | a: list[int] | None = [],
277 277 | b: Optional[Dict[int, int]] = {},
@ -368,7 +368,7 @@ B006_B008.py:279:80: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
276 276 | a: list[int] | None = [],
277 277 | b: Optional[Dict[int, int]] = {},
278 278 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(),
@ -389,7 +389,7 @@ B006_B008.py:284:52: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
281 281 | pass
282 282 |
283 283 |
@ -411,7 +411,7 @@ B006_B008.py:288:52: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
285 285 | """Docstring"""
286 286 |
287 287 |
@ -432,7 +432,7 @@ B006_B008.py:293:52: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
290 290 | ...
291 291 |
292 292 |
@ -453,7 +453,7 @@ B006_B008.py:297:52: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
294 294 | """Docstring"""; ...
295 295 |
296 296 |
@ -476,7 +476,7 @@ B006_B008.py:302:52: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
299 299 | ...
300 300 |
301 301 |
@ -508,7 +508,7 @@ B006_B008.py:313:52: B006 [*] Do not use mutable data structures for argument de
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
310 310 | """Docstring"""
311 311 |
312 312 |

View File

@ -21,7 +21,7 @@ B007.py:18:13: B007 [*] Loop control variable `k` not used within loop body
|
= help: Rename unused `k` to `_k`
Suggested fix
Unsafe fix
15 15 |
16 16 | for i in range(10):
17 17 | for j in range(10):
@ -47,7 +47,7 @@ B007.py:30:13: B007 [*] Loop control variable `k` not used within loop body
|
= help: Rename unused `k` to `_k`
Suggested fix
Unsafe fix
27 27 | yield i, (j, (k, l))
28 28 |
29 29 |
@ -110,7 +110,7 @@ B007.py:52:14: B007 [*] Loop control variable `bar` not used within loop body
|
= help: Rename unused `bar` to `_bar`
Suggested fix
Unsafe fix
49 49 |
50 50 | def f():
51 51 | # Fixable.
@ -142,7 +142,7 @@ B007.py:68:14: B007 [*] Loop control variable `bar` not used within loop body
|
= help: Rename unused `bar` to `_bar`
Suggested fix
Unsafe fix
65 65 |
66 66 | def f():
67 67 | # Fixable.

View File

@ -11,7 +11,7 @@ B009_B010.py:19:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
16 16 | getattr(foo, "__123abc")
17 17 |
18 18 | # Invalid usage
@ -32,7 +32,7 @@ B009_B010.py:20:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
17 17 |
18 18 | # Invalid usage
19 19 | getattr(foo, "bar")
@ -53,7 +53,7 @@ B009_B010.py:21:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
18 18 | # Invalid usage
19 19 | getattr(foo, "bar")
20 20 | getattr(foo, "_123abc")
@ -74,7 +74,7 @@ B009_B010.py:22:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
19 19 | getattr(foo, "bar")
20 20 | getattr(foo, "_123abc")
21 21 | getattr(foo, "__123abc__")
@ -95,7 +95,7 @@ B009_B010.py:23:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
20 20 | getattr(foo, "_123abc")
21 21 | getattr(foo, "__123abc__")
22 22 | getattr(foo, "abc123")
@ -116,7 +116,7 @@ B009_B010.py:24:15: B009 [*] Do not call `getattr` with a constant attribute val
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
21 21 | getattr(foo, "__123abc__")
22 22 | getattr(foo, "abc123")
23 23 | getattr(foo, r"abc123")
@ -137,7 +137,7 @@ B009_B010.py:25:4: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
22 22 | getattr(foo, "abc123")
23 23 | getattr(foo, r"abc123")
24 24 | _ = lambda x: getattr(x, "bar")
@ -158,7 +158,7 @@ B009_B010.py:27:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
24 24 | _ = lambda x: getattr(x, "bar")
25 25 | if getattr(x, "bar"):
26 26 | pass
@ -179,7 +179,7 @@ B009_B010.py:28:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
25 25 | if getattr(x, "bar"):
26 26 | pass
27 27 | getattr(1, "real")
@ -200,7 +200,7 @@ B009_B010.py:29:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
26 26 | pass
27 27 | getattr(1, "real")
28 28 | getattr(1., "real")
@ -221,7 +221,7 @@ B009_B010.py:30:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
27 27 | getattr(1, "real")
28 28 | getattr(1., "real")
29 29 | getattr(1.0, "real")
@ -242,7 +242,7 @@ B009_B010.py:31:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
28 28 | getattr(1., "real")
29 29 | getattr(1.0, "real")
30 30 | getattr(1j, "real")
@ -263,7 +263,7 @@ B009_B010.py:32:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
29 29 | getattr(1.0, "real")
30 30 | getattr(1j, "real")
31 31 | getattr(True, "real")
@ -284,7 +284,7 @@ B009_B010.py:33:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
30 30 | getattr(1j, "real")
31 31 | getattr(True, "real")
32 32 | getattr(x := 1, "real")
@ -304,7 +304,7 @@ B009_B010.py:34:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
31 31 | getattr(True, "real")
32 32 | getattr(x := 1, "real")
33 33 | getattr(x + y, "real")
@ -326,7 +326,7 @@ B009_B010.py:58:8: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
55 55 | setattr(foo.bar, r"baz", None)
56 56 |
57 57 | # Regression test for: https://github.com/astral-sh/ruff/issues/7455#issuecomment-1722458885
@ -345,7 +345,7 @@ B009_B010.py:65:1: B009 [*] Do not call `getattr` with a constant attribute valu
|
= help: Replace `getattr` with attribute access
Suggested fix
Unsafe fix
62 62 | setattr(*foo, "bar", None)
63 63 |
64 64 | # Regression test for: https://github.com/astral-sh/ruff/issues/7455#issuecomment-1739800901

View File

@ -11,7 +11,7 @@ B009_B010.py:50:1: B010 [*] Do not call `setattr` with a constant attribute valu
|
= help: Replace `setattr` with assignment
Suggested fix
Unsafe fix
47 47 | pass
48 48 |
49 49 | # Invalid usage
@ -32,7 +32,7 @@ B009_B010.py:51:1: B010 [*] Do not call `setattr` with a constant attribute valu
|
= help: Replace `setattr` with assignment
Suggested fix
Unsafe fix
48 48 |
49 49 | # Invalid usage
50 50 | setattr(foo, "bar", None)
@ -53,7 +53,7 @@ B009_B010.py:52:1: B010 [*] Do not call `setattr` with a constant attribute valu
|
= help: Replace `setattr` with assignment
Suggested fix
Unsafe fix
49 49 | # Invalid usage
50 50 | setattr(foo, "bar", None)
51 51 | setattr(foo, "_123abc", None)
@ -74,7 +74,7 @@ B009_B010.py:53:1: B010 [*] Do not call `setattr` with a constant attribute valu
|
= help: Replace `setattr` with assignment
Suggested fix
Unsafe fix
50 50 | setattr(foo, "bar", None)
51 51 | setattr(foo, "_123abc", None)
52 52 | setattr(foo, "__123abc__", None)
@ -94,7 +94,7 @@ B009_B010.py:54:1: B010 [*] Do not call `setattr` with a constant attribute valu
|
= help: Replace `setattr` with assignment
Suggested fix
Unsafe fix
51 51 | setattr(foo, "_123abc", None)
52 52 | setattr(foo, "__123abc__", None)
53 53 | setattr(foo, "abc123", None)
@ -115,7 +115,7 @@ B009_B010.py:55:1: B010 [*] Do not call `setattr` with a constant attribute valu
|
= help: Replace `setattr` with assignment
Suggested fix
Unsafe fix
52 52 | setattr(foo, "__123abc__", None)
53 53 | setattr(foo, "abc123", None)
54 54 | setattr(foo, r"abc123", None)

View File

@ -11,7 +11,7 @@ B011.py:8:8: B011 [*] Do not `assert False` (`python -O` removes these calls), r
|
= help: Replace `assert False`
Suggested fix
Unsafe fix
5 5 | """
6 6 |
7 7 | assert 1 != 2
@ -29,7 +29,7 @@ B011.py:10:8: B011 [*] Do not `assert False` (`python -O` removes these calls),
|
= help: Replace `assert False`
Suggested fix
Unsafe fix
7 7 | assert 1 != 2
8 8 | assert False
9 9 | assert 1 != 2, "message"

View File

@ -9,7 +9,7 @@ B006_extended.py:17:55: B006 [*] Do not use mutable data structures for argument
|
= help: Replace with `None`; initialize within function
Possible fix
Manual fix
14 14 | ...
15 15 |
16 16 |

View File

@ -325,7 +325,9 @@ pub(crate) fn trailing_commas(
let comma = prev.spanned.unwrap();
let mut diagnostic = Diagnostic::new(ProhibitedTrailingComma, comma.1);
if settings.rules.should_fix(Rule::ProhibitedTrailingComma) {
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(diagnostic.range())));
diagnostic.set_fix(Fix::automatic_safe(Edit::range_deletion(
diagnostic.range(),
)));
}
diagnostics.push(diagnostic);
}
@ -365,7 +367,7 @@ pub(crate) fn trailing_commas(
// removing any brackets in the same linter pass - doing both at the same time could
// lead to a syntax error.
let contents = locator.slice(missing_comma.1);
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
format!("{contents},"),
missing_comma.1,
)));

View File

@ -1293,7 +1293,7 @@ pub(crate) fn fix_unnecessary_comprehension_any_all(
_ => whitespace_after_arg,
};
Ok(Fix::suggested(Edit::range_replacement(
Ok(Fix::automatic_unsafe(Edit::range_replacement(
tree.codegen_stylist(stylist),
expr.range(),
)))

View File

@ -90,9 +90,9 @@ pub(crate) fn unnecessary_call_around_sorted(
checker.stylist(),
)?;
if outer.id == "reversed" {
Ok(Fix::suggested(edit))
Ok(Fix::automatic_unsafe(edit))
} else {
Ok(Fix::automatic(edit))
Ok(Fix::automatic_safe(edit))
}
});
}

View File

@ -88,7 +88,7 @@ pub(crate) fn unnecessary_collection_call(
);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_collection_call(expr, checker).map(Fix::suggested)
fixes::fix_unnecessary_collection_call(expr, checker).map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -67,7 +67,7 @@ fn add_diagnostic(checker: &mut Checker, expr: &Expr) {
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_comprehension(expr, checker.locator(), checker.stylist())
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -137,7 +137,7 @@ pub(crate) fn unnecessary_double_cast_or_process(
checker.locator(),
checker.stylist(),
)
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -69,7 +69,7 @@ pub(crate) fn unnecessary_generator_dict(
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, expr.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_generator_dict(expr, checker).map(Fix::suggested)
fixes::fix_unnecessary_generator_dict(expr, checker).map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -63,7 +63,7 @@ pub(crate) fn unnecessary_generator_list(
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_generator_list(expr, checker.locator(), checker.stylist())
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -62,7 +62,7 @@ pub(crate) fn unnecessary_generator_set(
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorSet, expr.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_generator_set(expr, checker).map(Fix::suggested)
fixes::fix_unnecessary_generator_set(expr, checker).map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -59,7 +59,7 @@ pub(crate) fn unnecessary_list_call(
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_list_call(expr, checker.locator(), checker.stylist())
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -67,7 +67,7 @@ pub(crate) fn unnecessary_list_comprehension_dict(
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, expr.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_list_comprehension_dict(expr, checker).map(Fix::suggested)
fixes::fix_unnecessary_list_comprehension_dict(expr, checker).map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -60,7 +60,8 @@ pub(crate) fn unnecessary_list_comprehension_set(
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, expr.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_list_comprehension_set(expr, checker).map(Fix::suggested)
fixes::fix_unnecessary_list_comprehension_set(expr, checker)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -81,8 +81,9 @@ pub(crate) fn unnecessary_literal_dict(
expr.range(),
);
if checker.patch(diagnostic.kind.rule()) {
diagnostic
.try_set_fix(|| fixes::fix_unnecessary_literal_dict(expr, checker).map(Fix::suggested));
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_literal_dict(expr, checker).map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);
}

View File

@ -76,8 +76,9 @@ pub(crate) fn unnecessary_literal_set(
expr.range(),
);
if checker.patch(diagnostic.kind.rule()) {
diagnostic
.try_set_fix(|| fixes::fix_unnecessary_literal_set(expr, checker).map(Fix::suggested));
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_literal_set(expr, checker).map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);
}

View File

@ -98,7 +98,7 @@ pub(crate) fn unnecessary_literal_within_dict_call(
checker.locator(),
checker.stylist(),
)
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -100,7 +100,7 @@ pub(crate) fn unnecessary_literal_within_list_call(
checker.locator(),
checker.stylist(),
)
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -102,7 +102,7 @@ pub(crate) fn unnecessary_literal_within_tuple_call(
checker.locator(),
checker.stylist(),
)
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -230,7 +230,7 @@ pub(crate) fn unnecessary_map(
checker.locator(),
checker.stylist(),
)
.map(Fix::suggested)
.map(Fix::automatic_unsafe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -10,7 +10,7 @@ C400.py:1:5: C400 [*] Unnecessary generator (rewrite as a `list` comprehension)
|
= help: Rewrite as a `list` comprehension
Suggested fix
Unsafe fix
1 |-x = list(x for x in range(3))
1 |+x = [x for x in range(3)]
2 2 | x = list(
@ -28,7 +28,7 @@ C400.py:2:5: C400 [*] Unnecessary generator (rewrite as a `list` comprehension)
|
= help: Rewrite as a `list` comprehension
Suggested fix
Unsafe fix
1 1 | x = list(x for x in range(3))
2 |-x = list(
2 |+x = [

View File

@ -10,7 +10,7 @@ C401.py:1:5: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
1 |-x = set(x for x in range(3))
1 |+x = {x for x in range(3)}
2 2 | x = set(x for x in range(3))
@ -27,7 +27,7 @@ C401.py:2:5: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
1 1 | x = set(x for x in range(3))
2 |-x = set(x for x in range(3))
2 |+x = {x for x in range(3)}
@ -46,7 +46,7 @@ C401.py:3:8: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
1 1 | x = set(x for x in range(3))
2 2 | x = set(x for x in range(3))
3 |-y = f"{set(a if a < 6 else 0 for a in range(3))}"
@ -65,7 +65,7 @@ C401.py:4:17: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
1 1 | x = set(x for x in range(3))
2 2 | x = set(x for x in range(3))
3 3 | y = f"{set(a if a < 6 else 0 for a in range(3))}"
@ -84,7 +84,7 @@ C401.py:5:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
2 2 | x = set(x for x in range(3))
3 3 | y = f"{set(a if a < 6 else 0 for a in range(3))}"
4 4 | _ = "{}".format(set(a if a < 6 else 0 for a in range(3)))
@ -103,7 +103,7 @@ C401.py:12:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
9 9 | return x
10 10 |
11 11 |
@ -123,7 +123,7 @@ C401.py:13:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
10 10 |
11 11 |
12 12 | print(f'Hello {set(a for a in "abc")} World')
@ -144,7 +144,7 @@ C401.py:14:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
11 11 |
12 12 | print(f'Hello {set(a for a in "abc")} World')
13 13 | print(f"Hello {set(a for a in 'abc')} World")
@ -164,7 +164,7 @@ C401.py:15:10: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
12 12 | print(f'Hello {set(a for a in "abc")} World')
13 13 | print(f"Hello {set(a for a in 'abc')} World")
14 14 | print(f"Hello {set(f(a) for a in 'abc')} World")
@ -184,7 +184,7 @@ C401.py:15:34: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
12 12 | print(f'Hello {set(a for a in "abc")} World')
13 13 | print(f"Hello {set(a for a in 'abc')} World")
14 14 | print(f"Hello {set(f(a) for a in 'abc')} World")
@ -205,7 +205,7 @@ C401.py:16:11: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
13 13 | print(f"Hello {set(a for a in 'abc')} World")
14 14 | print(f"Hello {set(f(a) for a in 'abc')} World")
15 15 | print(f"{set(a for a in 'abc') - set(a for a in 'ab')}")
@ -226,7 +226,7 @@ C401.py:16:35: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
13 13 | print(f"Hello {set(a for a in 'abc')} World")
14 14 | print(f"Hello {set(f(a) for a in 'abc')} World")
15 15 | print(f"{set(a for a in 'abc') - set(a for a in 'ab')}")
@ -245,7 +245,7 @@ C401.py:20:12: C401 [*] Unnecessary generator (rewrite as a `set` comprehension)
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
17 17 |
18 18 | # The fix generated for this diagnostic is incorrect, as we add additional space
19 19 | # around the set comprehension.

View File

@ -10,7 +10,7 @@ C402.py:1:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
1 |-dict((x, x) for x in range(3))
1 |+{x: x for x in range(3)}
2 2 | dict(
@ -29,7 +29,7 @@ C402.py:2:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
1 1 | dict((x, x) for x in range(3))
2 |-dict(
3 |- (x, x) for x in range(3)
@ -52,7 +52,7 @@ C402.py:6:8: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
3 3 | (x, x) for x in range(3)
4 4 | )
5 5 | dict(((x, x) for x in range(3)), z=3)
@ -73,7 +73,7 @@ C402.py:7:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
4 4 | )
5 5 | dict(((x, x) for x in range(3)), z=3)
6 6 | y = f'{dict((x, x) for x in range(3))}'
@ -94,7 +94,7 @@ C402.py:8:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
5 5 | dict(((x, x) for x in range(3)), z=3)
6 6 | y = f'{dict((x, x) for x in range(3))}'
7 7 | print(f'Hello {dict((x, x) for x in range(3))} World')
@ -114,7 +114,7 @@ C402.py:9:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
6 6 | y = f'{dict((x, x) for x in range(3))}'
7 7 | print(f'Hello {dict((x, x) for x in range(3))} World')
8 8 | print(f"Hello {dict((x, x) for x in 'abc')} World")
@ -135,7 +135,7 @@ C402.py:10:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
7 7 | print(f'Hello {dict((x, x) for x in range(3))} World')
8 8 | print(f"Hello {dict((x, x) for x in 'abc')} World")
9 9 | print(f'Hello {dict((x, x) for x in "abc")} World')
@ -155,7 +155,7 @@ C402.py:12:4: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
9 9 | print(f'Hello {dict((x, x) for x in "abc")} World')
10 10 | print(f'Hello {dict((x,x) for x in "abc")} World')
11 11 |
@ -175,7 +175,7 @@ C402.py:12:37: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
9 9 | print(f'Hello {dict((x, x) for x in "abc")} World')
10 10 | print(f'Hello {dict((x,x) for x in "abc")} World')
11 11 |
@ -195,7 +195,7 @@ C402.py:13:5: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
10 10 | print(f'Hello {dict((x,x) for x in "abc")} World')
11 11 |
12 12 | f'{dict((x, x) for x in range(3)) | dict((x, x) for x in range(3))}'
@ -215,7 +215,7 @@ C402.py:13:38: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
10 10 | print(f'Hello {dict((x,x) for x in "abc")} World')
11 11 |
12 12 | f'{dict((x, x) for x in range(3)) | dict((x, x) for x in range(3))}'
@ -236,7 +236,7 @@ C402.py:18:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
15 15 | def f(x):
16 16 | return x
17 17 |
@ -256,7 +256,7 @@ C402.py:21:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension)
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
18 18 | print(f'Hello {dict((x,f(x)) for x in "abc")} World')
19 19 |
20 20 | # Regression test for: https://github.com/astral-sh/ruff/issues/7086

View File

@ -10,7 +10,7 @@ C403.py:1:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
1 |-s = set([x for x in range(3)])
1 |+s = {x for x in range(3)}
2 2 | s = set(
@ -30,7 +30,7 @@ C403.py:2:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
1 1 | s = set([x for x in range(3)])
2 |-s = set(
3 |- [x for x in range(3)]
@ -52,7 +52,7 @@ C403.py:6:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
3 3 | [x for x in range(3)]
4 4 | )
5 5 |
@ -72,7 +72,7 @@ C403.py:7:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` compr
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
4 4 | )
5 5 |
6 6 | s = f"{set([x for x in 'ab'])}"
@ -93,7 +93,7 @@ C403.py:12:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
9 9 | def f(x):
10 10 | return x
11 11 |
@ -113,7 +113,7 @@ C403.py:14:9: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
11 11 |
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 |
@ -131,7 +131,7 @@ C403.py:14:34: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` com
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
11 11 |
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 |
@ -147,7 +147,7 @@ C403.py:15:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comp
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 |
14 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
@ -162,7 +162,7 @@ C403.py:15:33: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` com
|
= help: Rewrite as a `set` comprehension
Suggested fix
Unsafe fix
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 |
14 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"

View File

@ -9,7 +9,7 @@ C404.py:1:1: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
1 |-dict([(i, i) for i in range(3)])
1 |+{i: i for i in range(3)}
2 2 | dict([(i, i) for i in range(3)], z=4)
@ -27,7 +27,7 @@ C404.py:7:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
4 4 | def f(x):
5 5 | return x
6 6 |
@ -47,7 +47,7 @@ C404.py:8:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
5 5 | return x
6 6 |
7 7 | f'{dict([(s,s) for s in "ab"])}'
@ -67,7 +67,7 @@ C404.py:9:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comp
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
6 6 |
7 7 | f'{dict([(s,s) for s in "ab"])}'
8 8 | f"{dict([(s,s) for s in 'ab'])}"
@ -88,7 +88,7 @@ C404.py:10:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
7 7 | f'{dict([(s,s) for s in "ab"])}'
8 8 | f"{dict([(s,s) for s in 'ab'])}"
9 9 | f"{dict([(s, s) for s in 'ab'])}"
@ -108,7 +108,7 @@ C404.py:12:4: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
9 9 | f"{dict([(s, s) for s in 'ab'])}"
10 10 | f"{dict([(s,f(s)) for s in 'ab'])}"
11 11 |
@ -128,7 +128,7 @@ C404.py:12:34: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` co
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
9 9 | f"{dict([(s, s) for s in 'ab'])}"
10 10 | f"{dict([(s,f(s)) for s in 'ab'])}"
11 11 |
@ -148,7 +148,7 @@ C404.py:13:5: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` com
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
10 10 | f"{dict([(s,f(s)) for s in 'ab'])}"
11 11 |
12 12 | f'{dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"])}'
@ -168,7 +168,7 @@ C404.py:13:35: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` co
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
10 10 | f"{dict([(s,f(s)) for s in 'ab'])}"
11 11 |
12 12 | f'{dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"])}'
@ -186,7 +186,7 @@ C404.py:16:14: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` co
|
= help: Rewrite as a `dict` comprehension
Suggested fix
Unsafe fix
13 13 | f'{ dict([(s,s) for s in "ab"]) | dict([(s,s) for s in "ab"]) }'
14 14 |
15 15 | # Regression test for: https://github.com/astral-sh/ruff/issues/7087

View File

@ -10,7 +10,7 @@ C405.py:1:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
1 |-set([1, 2])
1 |+{1, 2}
2 2 | set((1, 2))
@ -27,7 +27,7 @@ C405.py:2:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
1 1 | set([1, 2])
2 |-set((1, 2))
2 |+{1, 2}
@ -46,7 +46,7 @@ C405.py:3:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
1 1 | set([1, 2])
2 2 | set((1, 2))
3 |-set([])
@ -66,7 +66,7 @@ C405.py:4:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
1 1 | set([1, 2])
2 2 | set((1, 2))
3 3 | set([])
@ -88,7 +88,7 @@ C405.py:6:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
3 3 | set([])
4 4 | set(())
5 5 | set()
@ -111,7 +111,7 @@ C405.py:7:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
4 4 | set(())
5 5 | set()
6 6 | set((1,))
@ -137,7 +137,7 @@ C405.py:10:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
7 7 | set((
8 8 | 1,
9 9 | ))
@ -163,7 +163,7 @@ C405.py:13:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
10 10 | set([
11 11 | 1,
12 12 | ])
@ -188,7 +188,7 @@ C405.py:16:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
13 13 | set(
14 14 | (1,)
15 15 | )
@ -211,7 +211,7 @@ C405.py:19:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
16 16 | set(
17 17 | [1,]
18 18 | )
@ -231,7 +231,7 @@ C405.py:20:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
17 17 | [1,]
18 18 | )
19 19 | f"{set([1,2,3])}"
@ -252,7 +252,7 @@ C405.py:21:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
18 18 | )
19 19 | f"{set([1,2,3])}"
20 20 | f"{set(['a', 'b'])}"
@ -273,7 +273,7 @@ C405.py:23:4: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
20 20 | f"{set(['a', 'b'])}"
21 21 | f'{set(["a", "b"])}'
22 22 |
@ -294,7 +294,7 @@ C405.py:23:22: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
20 20 | f"{set(['a', 'b'])}"
21 21 | f'{set(["a", "b"])}'
22 22 |
@ -314,7 +314,7 @@ C405.py:24:5: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
21 21 | f'{set(["a", "b"])}'
22 22 |
23 23 | f"{set(['a', 'b']) - set(['a'])}"
@ -333,7 +333,7 @@ C405.py:24:23: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
21 21 | f'{set(["a", "b"])}'
22 22 |
23 23 | f"{set(['a', 'b']) - set(['a'])}"
@ -352,7 +352,7 @@ C405.py:25:6: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
22 22 |
23 23 | f"{set(['a', 'b']) - set(['a'])}"
24 24 | f"{ set(['a', 'b']) - set(['a']) }"
@ -370,7 +370,7 @@ C405.py:25:24: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
22 22 |
23 23 | f"{set(['a', 'b']) - set(['a'])}"
24 24 | f"{ set(['a', 'b']) - set(['a']) }"
@ -387,7 +387,7 @@ C405.py:26:7: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
23 23 | f"{set(['a', 'b']) - set(['a'])}"
24 24 | f"{ set(['a', 'b']) - set(['a']) }"
25 25 | f"a {set(['a', 'b']) - set(['a'])} b"
@ -403,7 +403,7 @@ C405.py:26:25: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal)
|
= help: Rewrite as a `set` literal
Suggested fix
Unsafe fix
23 23 | f"{set(['a', 'b']) - set(['a'])}"
24 24 | f"{ set(['a', 'b']) - set(['a']) }"
25 25 | f"a {set(['a', 'b']) - set(['a'])} b"

View File

@ -10,7 +10,7 @@ C406.py:1:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal)
|
= help: Rewrite as a `dict` literal
Suggested fix
Unsafe fix
1 |-d1 = dict([(1, 2)])
1 |+d1 = {1: 2}
2 2 | d2 = dict(((1, 2),))
@ -27,7 +27,7 @@ C406.py:2:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal)
|
= help: Rewrite as a `dict` literal
Suggested fix
Unsafe fix
1 1 | d1 = dict([(1, 2)])
2 |-d2 = dict(((1, 2),))
2 |+d2 = {1: 2,}
@ -46,7 +46,7 @@ C406.py:3:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal)
|
= help: Rewrite as a `dict` literal
Suggested fix
Unsafe fix
1 1 | d1 = dict([(1, 2)])
2 2 | d2 = dict(((1, 2),))
3 |-d3 = dict([])
@ -64,7 +64,7 @@ C406.py:4:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal)
|
= help: Rewrite as a `dict` literal
Suggested fix
Unsafe fix
1 1 | d1 = dict([(1, 2)])
2 2 | d2 = dict(((1, 2),))
3 3 | d3 = dict([])

View File

@ -10,7 +10,7 @@ C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
1 |-t = tuple()
1 |+t = ()
2 2 | l = list()
@ -27,7 +27,7 @@ C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
1 1 | t = tuple()
2 |-l = list()
2 |+l = []
@ -46,7 +46,7 @@ C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
1 1 | t = tuple()
2 2 | l = list()
3 |-d1 = dict()
@ -65,7 +65,7 @@ C408.py:4:6: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
1 1 | t = tuple()
2 2 | l = list()
3 3 | d1 = dict()
@ -86,7 +86,7 @@ C408.py:14:4: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
11 11 |
12 12 | a = list()
13 13 |
@ -106,7 +106,7 @@ C408.py:15:4: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
12 12 | a = list()
13 13 |
14 14 | f"{dict(x='y')}"
@ -126,7 +126,7 @@ C408.py:16:4: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
13 13 |
14 14 | f"{dict(x='y')}"
15 15 | f'{dict(x="y")}'
@ -147,7 +147,7 @@ C408.py:17:6: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
14 14 | f"{dict(x='y')}"
15 15 | f'{dict(x="y")}'
16 16 | f"{dict()}"
@ -168,7 +168,7 @@ C408.py:19:4: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
16 16 | f"{dict()}"
17 17 | f"a {dict()} b"
18 18 |
@ -189,7 +189,7 @@ C408.py:19:18: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
16 16 | f"{dict()}"
17 17 | f"a {dict()} b"
18 18 |
@ -209,7 +209,7 @@ C408.py:20:5: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
17 17 | f"a {dict()} b"
18 18 |
19 19 | f"{dict(x='y') | dict(y='z')}"
@ -228,7 +228,7 @@ C408.py:20:19: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
17 17 | f"a {dict()} b"
18 18 |
19 19 | f"{dict(x='y') | dict(y='z')}"
@ -247,7 +247,7 @@ C408.py:21:6: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
18 18 |
19 19 | f"{dict(x='y') | dict(y='z')}"
20 20 | f"{ dict(x='y') | dict(y='z') }"
@ -265,7 +265,7 @@ C408.py:21:20: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
18 18 |
19 19 | f"{dict(x='y') | dict(y='z')}"
20 20 | f"{ dict(x='y') | dict(y='z') }"
@ -282,7 +282,7 @@ C408.py:22:7: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
19 19 | f"{dict(x='y') | dict(y='z')}"
20 20 | f"{ dict(x='y') | dict(y='z') }"
21 21 | f"a {dict(x='y') | dict(y='z')} b"
@ -298,7 +298,7 @@ C408.py:22:21: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
19 19 | f"{dict(x='y') | dict(y='z')}"
20 20 | f"{ dict(x='y') | dict(y='z') }"
21 21 | f"a {dict(x='y') | dict(y='z')} b"

View File

@ -10,7 +10,7 @@ C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
1 |-t = tuple()
1 |+t = ()
2 2 | l = list()
@ -27,7 +27,7 @@ C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
1 1 | t = tuple()
2 |-l = list()
2 |+l = []
@ -46,7 +46,7 @@ C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
1 1 | t = tuple()
2 2 | l = list()
3 |-d1 = dict()
@ -65,7 +65,7 @@ C408.py:16:4: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
13 13 |
14 14 | f"{dict(x='y')}"
15 15 | f'{dict(x="y")}'
@ -86,7 +86,7 @@ C408.py:17:6: C408 [*] Unnecessary `dict` call (rewrite as a literal)
|
= help: Rewrite as a literal
Suggested fix
Unsafe fix
14 14 | f"{dict(x='y')}"
15 15 | f'{dict(x="y")}'
16 16 | f"{dict()}"

View File

@ -10,7 +10,7 @@ C409.py:1:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as
|
= help: Rewrite as a `tuple` literal
Suggested fix
Unsafe fix
1 |-t1 = tuple([])
1 |+t1 = ()
2 2 | t2 = tuple([1, 2])
@ -27,7 +27,7 @@ C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as
|
= help: Rewrite as a `tuple` literal
Suggested fix
Unsafe fix
1 1 | t1 = tuple([])
2 |-t2 = tuple([1, 2])
2 |+t2 = (1, 2)
@ -46,7 +46,7 @@ C409.py:3:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove th
|
= help: Remove outer `tuple` call
Suggested fix
Unsafe fix
1 1 | t1 = tuple([])
2 2 | t2 = tuple([1, 2])
3 |-t3 = tuple((1, 2))
@ -70,7 +70,7 @@ C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as
|
= help: Rewrite as a `tuple` literal
Suggested fix
Unsafe fix
1 1 | t1 = tuple([])
2 2 | t2 = tuple([1, 2])
3 3 | t3 = tuple((1, 2))
@ -96,7 +96,7 @@ C409.py:8:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove th
|
= help: Remove outer `tuple` call
Suggested fix
Unsafe fix
5 5 | 1,
6 6 | 2
7 7 | ])

View File

@ -10,7 +10,7 @@ C410.py:1:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the
|
= help: Remove outer `list` call
Suggested fix
Unsafe fix
1 |-l1 = list([1, 2])
1 |+l1 = [1, 2]
2 2 | l2 = list((1, 2))
@ -27,7 +27,7 @@ C410.py:2:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as
|
= help: Rewrite as a `list` literal
Suggested fix
Unsafe fix
1 1 | l1 = list([1, 2])
2 |-l2 = list((1, 2))
2 |+l2 = [1, 2]
@ -44,7 +44,7 @@ C410.py:3:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the
|
= help: Remove outer `list` call
Suggested fix
Unsafe fix
1 1 | l1 = list([1, 2])
2 2 | l2 = list((1, 2))
3 |-l3 = list([])
@ -60,7 +60,7 @@ C410.py:4:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as
|
= help: Rewrite as a `list` literal
Suggested fix
Unsafe fix
1 1 | l1 = list([1, 2])
2 2 | l2 = list((1, 2))
3 3 | l3 = list([])

View File

@ -9,7 +9,7 @@ C411.py:2:1: C411 [*] Unnecessary `list` call (remove the outer call to `list()`
|
= help: Remove outer `list` call
Suggested fix
Unsafe fix
1 1 | x = [1, 2, 3]
2 |-list([i for i in x])
2 |+[i for i in x]

View File

@ -32,7 +32,7 @@ C413.py:4:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
1 1 | x = [2, 3, 1]
2 2 | list(x)
3 3 | list(sorted(x))
@ -53,7 +53,7 @@ C413.py:5:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
2 2 | list(x)
3 3 | list(sorted(x))
4 4 | reversed(sorted(x))
@ -74,7 +74,7 @@ C413.py:6:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
3 3 | list(sorted(x))
4 4 | reversed(sorted(x))
5 5 | reversed(sorted(x, key=lambda e: e))
@ -95,7 +95,7 @@ C413.py:7:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
4 4 | reversed(sorted(x))
5 5 | reversed(sorted(x, key=lambda e: e))
6 6 | reversed(sorted(x, reverse=True))
@ -116,7 +116,7 @@ C413.py:8:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
5 5 | reversed(sorted(x, key=lambda e: e))
6 6 | reversed(sorted(x, reverse=True))
7 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
@ -137,7 +137,7 @@ C413.py:9:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
6 6 | reversed(sorted(x, reverse=True))
7 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
8 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
@ -157,7 +157,7 @@ C413.py:10:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
7 7 | reversed(sorted(x, key=lambda e: e, reverse=True))
8 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
9 9 | reversed(sorted(x, reverse=False))
@ -178,7 +178,7 @@ C413.py:11:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
8 8 | reversed(sorted(x, reverse=True, key=lambda e: e))
9 9 | reversed(sorted(x, reverse=False))
10 10 | reversed(sorted(x, reverse=x))
@ -197,7 +197,7 @@ C413.py:14:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
11 11 | reversed(sorted(x, reverse=not x))
12 12 |
13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
@ -216,7 +216,7 @@ C413.py:15:1: C413 [*] Unnecessary `reversed` call around `sorted()`
|
= help: Remove unnecessary `reversed` call
Suggested fix
Unsafe fix
12 12 |
13 13 | # Regression test for: https://github.com/astral-sh/ruff/issues/7289
14 14 | reversed(sorted(i for i in range(42)))

View File

@ -11,7 +11,7 @@ C414.py:2:1: C414 [*] Unnecessary `list` call within `list()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
1 1 | x = [1, 2, 3]
2 |-list(list(x))
2 |+list(x)
@ -30,7 +30,7 @@ C414.py:3:1: C414 [*] Unnecessary `tuple` call within `list()`
|
= help: Remove the inner `tuple` call
Suggested fix
Unsafe fix
1 1 | x = [1, 2, 3]
2 2 | list(list(x))
3 |-list(tuple(x))
@ -50,7 +50,7 @@ C414.py:4:1: C414 [*] Unnecessary `list` call within `tuple()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
1 1 | x = [1, 2, 3]
2 2 | list(list(x))
3 3 | list(tuple(x))
@ -71,7 +71,7 @@ C414.py:5:1: C414 [*] Unnecessary `tuple` call within `tuple()`
|
= help: Remove the inner `tuple` call
Suggested fix
Unsafe fix
2 2 | list(list(x))
3 3 | list(tuple(x))
4 4 | tuple(list(x))
@ -92,7 +92,7 @@ C414.py:6:1: C414 [*] Unnecessary `set` call within `set()`
|
= help: Remove the inner `set` call
Suggested fix
Unsafe fix
3 3 | list(tuple(x))
4 4 | tuple(list(x))
5 5 | tuple(tuple(x))
@ -113,7 +113,7 @@ C414.py:7:1: C414 [*] Unnecessary `list` call within `set()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
4 4 | tuple(list(x))
5 5 | tuple(tuple(x))
6 6 | set(set(x))
@ -134,7 +134,7 @@ C414.py:8:1: C414 [*] Unnecessary `tuple` call within `set()`
|
= help: Remove the inner `tuple` call
Suggested fix
Unsafe fix
5 5 | tuple(tuple(x))
6 6 | set(set(x))
7 7 | set(list(x))
@ -155,7 +155,7 @@ C414.py:9:1: C414 [*] Unnecessary `sorted` call within `set()`
|
= help: Remove the inner `sorted` call
Suggested fix
Unsafe fix
6 6 | set(set(x))
7 7 | set(list(x))
8 8 | set(tuple(x))
@ -176,7 +176,7 @@ C414.py:10:1: C414 [*] Unnecessary `sorted` call within `set()`
|
= help: Remove the inner `sorted` call
Suggested fix
Unsafe fix
7 7 | set(list(x))
8 8 | set(tuple(x))
9 9 | set(sorted(x))
@ -197,7 +197,7 @@ C414.py:11:1: C414 [*] Unnecessary `reversed` call within `set()`
|
= help: Remove the inner `reversed` call
Suggested fix
Unsafe fix
8 8 | set(tuple(x))
9 9 | set(sorted(x))
10 10 | set(sorted(x, key=lambda y: y))
@ -218,7 +218,7 @@ C414.py:12:1: C414 [*] Unnecessary `list` call within `sorted()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
9 9 | set(sorted(x))
10 10 | set(sorted(x, key=lambda y: y))
11 11 | set(reversed(x))
@ -239,7 +239,7 @@ C414.py:13:1: C414 [*] Unnecessary `tuple` call within `sorted()`
|
= help: Remove the inner `tuple` call
Suggested fix
Unsafe fix
10 10 | set(sorted(x, key=lambda y: y))
11 11 | set(reversed(x))
12 12 | sorted(list(x))
@ -260,7 +260,7 @@ C414.py:14:1: C414 [*] Unnecessary `sorted` call within `sorted()`
|
= help: Remove the inner `sorted` call
Suggested fix
Unsafe fix
11 11 | set(reversed(x))
12 12 | sorted(list(x))
13 13 | sorted(tuple(x))
@ -281,7 +281,7 @@ C414.py:15:1: C414 [*] Unnecessary `sorted` call within `sorted()`
|
= help: Remove the inner `sorted` call
Suggested fix
Unsafe fix
12 12 | sorted(list(x))
13 13 | sorted(tuple(x))
14 14 | sorted(sorted(x))
@ -302,7 +302,7 @@ C414.py:16:1: C414 [*] Unnecessary `sorted` call within `sorted()`
|
= help: Remove the inner `sorted` call
Suggested fix
Unsafe fix
13 13 | sorted(tuple(x))
14 14 | sorted(sorted(x))
15 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo)
@ -323,7 +323,7 @@ C414.py:17:1: C414 [*] Unnecessary `reversed` call within `sorted()`
|
= help: Remove the inner `reversed` call
Suggested fix
Unsafe fix
14 14 | sorted(sorted(x))
15 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo)
16 16 | sorted(sorted(x, reverse=True), reverse=True)
@ -344,7 +344,7 @@ C414.py:18:1: C414 [*] Unnecessary `list` call within `sorted()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
15 15 | sorted(sorted(x, key=foo, reverse=False), reverse=False, key=foo)
16 16 | sorted(sorted(x, reverse=True), reverse=True)
17 17 | sorted(reversed(x))
@ -370,7 +370,7 @@ C414.py:19:1: C414 [*] Unnecessary `list` call within `tuple()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
17 17 | sorted(reversed(x))
18 18 | sorted(list(x), key=lambda y: y)
19 19 | tuple(
@ -394,7 +394,7 @@ C414.py:25:1: C414 [*] Unnecessary `set` call within `set()`
|
= help: Remove the inner `set` call
Suggested fix
Unsafe fix
22 22 | "o"]
23 23 | )
24 24 | )
@ -415,7 +415,7 @@ C414.py:26:1: C414 [*] Unnecessary `list` call within `set()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
23 23 | )
24 24 | )
25 25 | set(set())
@ -435,7 +435,7 @@ C414.py:27:1: C414 [*] Unnecessary `tuple` call within `set()`
|
= help: Remove the inner `tuple` call
Suggested fix
Unsafe fix
24 24 | )
25 25 | set(set())
26 26 | set(list())
@ -456,7 +456,7 @@ C414.py:28:1: C414 [*] Unnecessary `reversed` call within `sorted()`
|
= help: Remove the inner `reversed` call
Suggested fix
Unsafe fix
25 25 | set(set())
26 26 | set(list())
27 27 | set(tuple())
@ -482,7 +482,7 @@ C414.py:37:27: C414 [*] Unnecessary `list` call within `sorted()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
35 35 |
36 36 | # Preserve trailing comments.
37 37 | xxxxxxxxxxx_xxxxx_xxxxx = sorted(
@ -505,7 +505,7 @@ C414.py:44:27: C414 [*] Unnecessary `list` call within `sorted()`
|
= help: Remove the inner `list` call
Suggested fix
Unsafe fix
42 42 | )
43 43 |
44 44 | xxxxxxxxxxx_xxxxx_xxxxx = sorted(

View File

@ -12,7 +12,7 @@ C416.py:6:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
|
= help: Rewrite using `list()`
Suggested fix
Unsafe fix
3 3 | z = [(1,), (2,), (3,)]
4 4 | d = {"a": 1, "b": 2, "c": 3}
5 5 |
@ -32,7 +32,7 @@ C416.py:7:1: C416 [*] Unnecessary `set` comprehension (rewrite using `set()`)
|
= help: Rewrite using `set()`
Suggested fix
Unsafe fix
4 4 | d = {"a": 1, "b": 2, "c": 3}
5 5 |
6 6 | [i for i in x]
@ -53,7 +53,7 @@ C416.py:8:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
|
= help: Rewrite using `dict()`
Suggested fix
Unsafe fix
5 5 |
6 6 | [i for i in x]
7 7 | {i for i in x}
@ -74,7 +74,7 @@ C416.py:9:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
|
= help: Rewrite using `dict()`
Suggested fix
Unsafe fix
6 6 | [i for i in x]
7 7 | {i for i in x}
8 8 | {k: v for k, v in y}
@ -94,7 +94,7 @@ C416.py:10:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
|
= help: Rewrite using `list()`
Suggested fix
Unsafe fix
7 7 | {i for i in x}
8 8 | {k: v for k, v in y}
9 9 | {k: v for k, v in d.items()}
@ -115,7 +115,7 @@ C416.py:11:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
|
= help: Rewrite using `dict()`
Suggested fix
Unsafe fix
8 8 | {k: v for k, v in y}
9 9 | {k: v for k, v in d.items()}
10 10 | [(k, v) for k, v in d.items()]
@ -133,7 +133,7 @@ C416.py:24:70: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`
|
= help: Rewrite using `list()`
Suggested fix
Unsafe fix
21 21 | {k: v if v else None for k, v in y}
22 22 |
23 23 | # Regression test for: https://github.com/astral-sh/ruff/issues/7196

View File

@ -12,7 +12,7 @@ C417.py:3:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
1 1 | # Errors.
2 2 | nums = [1, 2, 3]
3 |-map(lambda x: x + 1, nums)
@ -32,7 +32,7 @@ C417.py:4:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
1 1 | # Errors.
2 2 | nums = [1, 2, 3]
3 3 | map(lambda x: x + 1, nums)
@ -53,7 +53,7 @@ C417.py:5:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehens
|
= help: Replace `map` with a `list` comprehension
Suggested fix
Unsafe fix
2 2 | nums = [1, 2, 3]
3 3 | map(lambda x: x + 1, nums)
4 4 | map(lambda x: str(x), nums)
@ -74,7 +74,7 @@ C417.py:6:1: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehensi
|
= help: Replace `map` with a `set` comprehension
Suggested fix
Unsafe fix
3 3 | map(lambda x: x + 1, nums)
4 4 | map(lambda x: str(x), nums)
5 5 | list(map(lambda x: x * 2, nums))
@ -95,7 +95,7 @@ C417.py:7:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehens
|
= help: Replace `map` with a `dict` comprehension
Suggested fix
Unsafe fix
4 4 | map(lambda x: str(x), nums)
5 5 | list(map(lambda x: x * 2, nums))
6 6 | set(map(lambda x: x % 2 == 0, nums))
@ -116,7 +116,7 @@ C417.py:8:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehens
|
= help: Replace `map` with a `dict` comprehension
Suggested fix
Unsafe fix
5 5 | list(map(lambda x: x * 2, nums))
6 6 | set(map(lambda x: x % 2 == 0, nums))
7 7 | dict(map(lambda v: (v, v**2), nums))
@ -137,7 +137,7 @@ C417.py:9:1: C417 [*] Unnecessary `map` usage (rewrite using a generator express
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
6 6 | set(map(lambda x: x % 2 == 0, nums))
7 7 | dict(map(lambda v: (v, v**2), nums))
8 8 | dict(map(lambda v: [v, v**2], nums))
@ -158,7 +158,7 @@ C417.py:10:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
7 7 | dict(map(lambda v: (v, v**2), nums))
8 8 | dict(map(lambda v: [v, v**2], nums))
9 9 | map(lambda: "const", nums)
@ -179,7 +179,7 @@ C417.py:11:13: C417 [*] Unnecessary `map` usage (rewrite using a generator expre
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
8 8 | dict(map(lambda v: [v, v**2], nums))
9 9 | map(lambda: "const", nums)
10 10 | map(lambda _: 3.0, nums)
@ -200,7 +200,7 @@ C417.py:12:5: C417 [*] Unnecessary `map` usage (rewrite using a generator expres
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
9 9 | map(lambda: "const", nums)
10 10 | map(lambda _: 3.0, nums)
11 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123)))
@ -220,7 +220,7 @@ C417.py:13:14: C417 [*] Unnecessary `map` usage (rewrite using a generator expre
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
10 10 | map(lambda _: 3.0, nums)
11 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123)))
12 12 | all(map(lambda v: isinstance(v, dict), nums))
@ -241,7 +241,7 @@ C417.py:14:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehen
|
= help: Replace `map` with a `list` comprehension
Suggested fix
Unsafe fix
11 11 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123)))
12 12 | all(map(lambda v: isinstance(v, dict), nums))
13 13 | filter(func, map(lambda v: v, nums))
@ -260,7 +260,7 @@ C417.py:17:8: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehens
|
= help: Replace `map` with a `set` comprehension
Suggested fix
Unsafe fix
14 14 | list(map(lambda x, y: x * y, nums))
15 15 |
16 16 | # When inside f-string, then the fix should be surrounded by whitespace
@ -281,7 +281,7 @@ C417.py:18:8: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehen
|
= help: Replace `map` with a `dict` comprehension
Suggested fix
Unsafe fix
15 15 |
16 16 | # When inside f-string, then the fix should be surrounded by whitespace
17 17 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}"
@ -301,7 +301,7 @@ C417.py:36:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
33 33 | map(lambda x: lambda: x, range(4))
34 34 |
35 35 | # Error: the `x` is overridden by the inner lambda.
@ -321,7 +321,7 @@ C417.py:47:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
44 44 | dict(map(lambda k, v: (k, v), keys, values))
45 45 |
46 46 | # Regression test for: https://github.com/astral-sh/ruff/issues/7121
@ -340,7 +340,7 @@ C417.py:48:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
45 45 |
46 46 | # Regression test for: https://github.com/astral-sh/ruff/issues/7121
47 47 | map(lambda x: x, y if y else z)
@ -357,7 +357,7 @@ C417.py:49:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expres
|
= help: Replace `map` with a generator expression
Suggested fix
Unsafe fix
46 46 | # Regression test for: https://github.com/astral-sh/ruff/issues/7121
47 47 | map(lambda x: x, y if y else z)
48 48 | map(lambda x: x, (y if y else z))

View File

@ -10,7 +10,7 @@ C418.py:1:1: C418 [*] Unnecessary `dict` literal passed to `dict()` (remove the
|
= help: Remove outer `dict` call
Suggested fix
Unsafe fix
1 |-dict({})
1 |+{}
2 2 | dict({'a': 1})
@ -27,7 +27,7 @@ C418.py:2:1: C418 [*] Unnecessary `dict` literal passed to `dict()` (remove the
|
= help: Remove outer `dict` call
Suggested fix
Unsafe fix
1 1 | dict({})
2 |-dict({'a': 1})
2 |+{'a': 1}
@ -46,7 +46,7 @@ C418.py:3:1: C418 [*] Unnecessary `dict` comprehension passed to `dict()` (remov
|
= help: Remove outer `dict` call
Suggested fix
Unsafe fix
1 1 | dict({})
2 2 | dict({'a': 1})
3 |-dict({'x': 1 for x in range(10)})
@ -68,7 +68,7 @@ C418.py:4:1: C418 [*] Unnecessary `dict` comprehension passed to `dict()` (remov
|
= help: Remove outer `dict` call
Suggested fix
Unsafe fix
1 1 | dict({})
2 2 | dict({'a': 1})
3 3 | dict({'x': 1 for x in range(10)})

View File

@ -10,7 +10,7 @@ C419.py:1:5: C419 [*] Unnecessary list comprehension.
|
= help: Remove unnecessary list comprehension
Suggested fix
Unsafe fix
1 |-any([x.id for x in bar])
1 |+any(x.id for x in bar)
2 2 | all([x.id for x in bar])
@ -27,7 +27,7 @@ C419.py:2:5: C419 [*] Unnecessary list comprehension.
|
= help: Remove unnecessary list comprehension
Suggested fix
Unsafe fix
1 1 | any([x.id for x in bar])
2 |-all([x.id for x in bar])
2 |+all(x.id for x in bar)
@ -46,7 +46,7 @@ C419.py:4:5: C419 [*] Unnecessary list comprehension.
|
= help: Remove unnecessary list comprehension
Suggested fix
Unsafe fix
1 1 | any([x.id for x in bar])
2 2 | all([x.id for x in bar])
3 3 | any( # first comment
@ -67,7 +67,7 @@ C419.py:7:5: C419 [*] Unnecessary list comprehension.
|
= help: Remove unnecessary list comprehension
Suggested fix
Unsafe fix
4 4 | [x.id for x in bar], # second comment
5 5 | ) # third comment
6 6 | all( # first comment
@ -88,7 +88,7 @@ C419.py:9:5: C419 [*] Unnecessary list comprehension.
|
= help: Remove unnecessary list comprehension
Suggested fix
Unsafe fix
6 6 | all( # first comment
7 7 | [x.id for x in bar], # second comment
8 8 | ) # third comment
@ -115,7 +115,7 @@ C419.py:24:5: C419 [*] Unnecessary list comprehension.
|
= help: Remove unnecessary list comprehension
Suggested fix
Unsafe fix
21 21 |
22 22 | # Special comment handling
23 23 | any(
@ -147,7 +147,7 @@ C419.py:35:5: C419 [*] Unnecessary list comprehension.
|
= help: Remove unnecessary list comprehension
Suggested fix
Unsafe fix
32 32 |
33 33 | # Weird case where the function call, opening bracket, and comment are all
34 34 | # on the same line.

View File

@ -293,7 +293,7 @@ fn generate_fix(
range: TextRange::default(),
});
Fix::suggested_edits(
Fix::automatic_unsafe_edits(
Edit::insertion(
format!(
"{}{}{}",

View File

@ -9,7 +9,7 @@ EM.py:5:24: EM101 [*] Exception must not use a string literal, assign to variabl
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
2 2 |
3 3 |
4 4 | def f_a():
@ -29,7 +29,7 @@ EM.py:18:24: EM102 [*] Exception must not use an f-string literal, assign to var
|
= help: Assign to variable; remove f-string literal
Suggested fix
Unsafe fix
15 15 |
16 16 | def f_b():
17 17 | example = "example"
@ -48,7 +48,7 @@ EM.py:22:24: EM103 [*] Exception must not use a `.format()` string directly, ass
|
= help: Assign to variable; remove `.format()` string
Suggested fix
Unsafe fix
19 19 |
20 20 |
21 21 | def f_c():
@ -77,7 +77,7 @@ EM.py:39:24: EM101 [*] Exception must not use a string literal, assign to variab
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
36 36 | def nested():
37 37 | msg = "hello"
38 38 |
@ -107,7 +107,7 @@ EM.py:51:28: EM101 [*] Exception must not use a string literal, assign to variab
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
48 48 |
49 49 | def f_fix_indentation_check(foo):
50 50 | if foo:
@ -128,7 +128,7 @@ EM.py:54:32: EM102 [*] Exception must not use an f-string literal, assign to var
|
= help: Assign to variable; remove f-string literal
Suggested fix
Unsafe fix
51 51 | raise RuntimeError("This is an example exception")
52 52 | else:
53 53 | if foo == "foo":
@ -148,7 +148,7 @@ EM.py:55:24: EM103 [*] Exception must not use a `.format()` string directly, ass
|
= help: Assign to variable; remove `.format()` string
Suggested fix
Unsafe fix
52 52 | else:
53 53 | if foo == "foo":
54 54 | raise RuntimeError(f"This is an exception: {foo}")

View File

@ -9,7 +9,7 @@ EM.py:5:24: EM101 [*] Exception must not use a string literal, assign to variabl
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
2 2 |
3 3 |
4 4 | def f_a():
@ -28,7 +28,7 @@ EM.py:9:24: EM101 [*] Exception must not use a string literal, assign to variabl
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
6 6 |
7 7 |
8 8 | def f_a_short():
@ -47,7 +47,7 @@ EM.py:13:24: EM101 [*] Exception must not use a string literal, assign to variab
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
10 10 |
11 11 |
12 12 | def f_a_empty():
@ -67,7 +67,7 @@ EM.py:18:24: EM102 [*] Exception must not use an f-string literal, assign to var
|
= help: Assign to variable; remove f-string literal
Suggested fix
Unsafe fix
15 15 |
16 16 | def f_b():
17 17 | example = "example"
@ -86,7 +86,7 @@ EM.py:22:24: EM103 [*] Exception must not use a `.format()` string directly, ass
|
= help: Assign to variable; remove `.format()` string
Suggested fix
Unsafe fix
19 19 |
20 20 |
21 21 | def f_c():
@ -115,7 +115,7 @@ EM.py:39:24: EM101 [*] Exception must not use a string literal, assign to variab
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
36 36 | def nested():
37 37 | msg = "hello"
38 38 |
@ -145,7 +145,7 @@ EM.py:51:28: EM101 [*] Exception must not use a string literal, assign to variab
|
= help: Assign to variable; remove string literal
Suggested fix
Unsafe fix
48 48 |
49 49 | def f_fix_indentation_check(foo):
50 50 | if foo:
@ -166,7 +166,7 @@ EM.py:54:32: EM102 [*] Exception must not use an f-string literal, assign to var
|
= help: Assign to variable; remove f-string literal
Suggested fix
Unsafe fix
51 51 | raise RuntimeError("This is an example exception")
52 52 | else:
53 53 | if foo == "foo":
@ -186,7 +186,7 @@ EM.py:55:24: EM103 [*] Exception must not use a `.format()` string directly, ass
|
= help: Assign to variable; remove `.format()` string
Suggested fix
Unsafe fix
52 52 | else:
53 53 | if foo == "foo":
54 54 | raise RuntimeError(f"This is an exception: {foo}")

View File

@ -69,7 +69,7 @@ pub(crate) fn shebang_leading_whitespace(
let prefix = TextRange::up_to(range.start());
let mut diagnostic = Diagnostic::new(ShebangLeadingWhitespace, prefix);
if settings.rules.should_fix(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(prefix)));
diagnostic.set_fix(Fix::automatic_safe(Edit::range_deletion(prefix)));
}
Some(diagnostic)
}

View File

@ -169,7 +169,7 @@ fn concatenate_strings(a_range: TextRange, b_range: TextRange, locator: &Locator
let concatenation = format!("{a_leading_quote}{a_body}{b_body}{a_trailing_quote}");
let range = TextRange::new(a_range.start(), b_range.end());
Some(Fix::automatic(Edit::range_replacement(
Some(Fix::automatic_safe(Edit::range_replacement(
concatenation,
range,
)))

View File

@ -86,7 +86,7 @@ pub(crate) fn unconventional_import_alias(
let scope = &checker.semantic().scopes[binding.scope];
let (edit, rest) =
Renamer::rename(name, expected_alias, scope, checker.semantic())?;
Ok(Fix::suggested_edits(edit, rest))
Ok(Fix::automatic_unsafe_edits(edit, rest))
});
}
}

View File

@ -11,7 +11,7 @@ defaults.py:6:12: ICN001 [*] `altair` should be imported as `alt`
|
= help: Alias `altair` to `alt`
Suggested fix
Unsafe fix
3 3 |
4 4 |
5 5 | def unconventional():
@ -43,7 +43,7 @@ defaults.py:8:12: ICN001 [*] `numpy` should be imported as `np`
|
= help: Alias `numpy` to `np`
Suggested fix
Unsafe fix
5 5 | def unconventional():
6 6 | import altair
7 7 | import matplotlib.pyplot
@ -64,7 +64,7 @@ defaults.py:9:12: ICN001 [*] `pandas` should be imported as `pd`
|
= help: Alias `pandas` to `pd`
Suggested fix
Unsafe fix
6 6 | import altair
7 7 | import matplotlib.pyplot
8 8 | import numpy
@ -85,7 +85,7 @@ defaults.py:10:12: ICN001 [*] `seaborn` should be imported as `sns`
|
= help: Alias `seaborn` to `sns`
Suggested fix
Unsafe fix
7 7 | import matplotlib.pyplot
8 8 | import numpy
9 9 | import pandas
@ -105,7 +105,7 @@ defaults.py:11:12: ICN001 [*] `tkinter` should be imported as `tk`
|
= help: Alias `tkinter` to `tk`
Suggested fix
Unsafe fix
8 8 | import numpy
9 9 | import pandas
10 10 | import seaborn
@ -124,7 +124,7 @@ defaults.py:12:12: ICN001 [*] `networkx` should be imported as `nx`
|
= help: Alias `networkx` to `nx`
Suggested fix
Unsafe fix
9 9 | import pandas
10 10 | import seaborn
11 11 | import tkinter
@ -144,7 +144,7 @@ defaults.py:16:22: ICN001 [*] `altair` should be imported as `alt`
|
= help: Alias `altair` to `alt`
Suggested fix
Unsafe fix
13 13 |
14 14 |
15 15 | def unconventional_aliases():
@ -165,7 +165,7 @@ defaults.py:17:33: ICN001 [*] `matplotlib.pyplot` should be imported as `plt`
|
= help: Alias `matplotlib.pyplot` to `plt`
Suggested fix
Unsafe fix
14 14 |
15 15 | def unconventional_aliases():
16 16 | import altair as altr
@ -186,7 +186,7 @@ defaults.py:18:21: ICN001 [*] `numpy` should be imported as `np`
|
= help: Alias `numpy` to `np`
Suggested fix
Unsafe fix
15 15 | def unconventional_aliases():
16 16 | import altair as altr
17 17 | import matplotlib.pyplot as plot
@ -207,7 +207,7 @@ defaults.py:19:22: ICN001 [*] `pandas` should be imported as `pd`
|
= help: Alias `pandas` to `pd`
Suggested fix
Unsafe fix
16 16 | import altair as altr
17 17 | import matplotlib.pyplot as plot
18 18 | import numpy as nmp
@ -228,7 +228,7 @@ defaults.py:20:23: ICN001 [*] `seaborn` should be imported as `sns`
|
= help: Alias `seaborn` to `sns`
Suggested fix
Unsafe fix
17 17 | import matplotlib.pyplot as plot
18 18 | import numpy as nmp
19 19 | import pandas as pdas
@ -248,7 +248,7 @@ defaults.py:21:23: ICN001 [*] `tkinter` should be imported as `tk`
|
= help: Alias `tkinter` to `tk`
Suggested fix
Unsafe fix
18 18 | import numpy as nmp
19 19 | import pandas as pdas
20 20 | import seaborn as sbrn
@ -269,7 +269,7 @@ defaults.py:22:24: ICN001 [*] `networkx` should be imported as `nx`
|
= help: Alias `networkx` to `nx`
Suggested fix
Unsafe fix
19 19 | import pandas as pdas
20 20 | import seaborn as sbrn
21 21 | import tkinter as tkr

View File

@ -12,7 +12,7 @@ tricky.py:7:16: ICN001 [*] `pandas` should be imported as `pd`
|
= help: Alias `pandas` to `pd`
Suggested fix
Unsafe fix
3 3 |
4 4 | def rename_global():
5 5 | try:

View File

@ -69,7 +69,7 @@ pub(crate) fn direct_logger_instantiation(checker: &mut Checker, call: &ast::Exp
checker.semantic(),
)?;
let reference_edit = Edit::range_replacement(binding, call.func.range());
Ok(Fix::suggested_edits(import_edit, [reference_edit]))
Ok(Fix::automatic_unsafe_edits(import_edit, [reference_edit]))
});
}
checker.diagnostics.push(diagnostic);

View File

@ -82,7 +82,7 @@ pub(crate) fn invalid_get_logger_argument(checker: &mut Checker, call: &ast::Exp
let mut diagnostic = Diagnostic::new(InvalidGetLoggerArgument, expr.range());
if checker.patch(diagnostic.kind.rule()) {
if checker.semantic().is_builtin("__name__") {
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
"__name__".to_string(),
expr.range(),
)));

View File

@ -63,7 +63,7 @@ pub(crate) fn undocumented_warn(checker: &mut Checker, expr: &Expr) {
checker.semantic(),
)?;
let reference_edit = Edit::range_replacement(binding, expr.range());
Ok(Fix::suggested_edits(import_edit, [reference_edit]))
Ok(Fix::automatic_unsafe_edits(import_edit, [reference_edit]))
});
}
checker.diagnostics.push(diagnostic);

View File

@ -12,7 +12,7 @@ LOG001.py:3:1: LOG001 [*] Use `logging.getLogger()` to instantiate loggers
|
= help: Replace with `logging.getLogger()`
Suggested fix
Unsafe fix
1 1 | import logging
2 2 |
3 |-logging.Logger(__name__)
@ -29,7 +29,7 @@ LOG001.py:4:1: LOG001 [*] Use `logging.getLogger()` to instantiate loggers
|
= help: Replace with `logging.getLogger()`
Suggested fix
Unsafe fix
1 1 | import logging
2 2 |
3 3 | logging.Logger(__name__)

View File

@ -10,7 +10,7 @@ LOG002.py:11:11: LOG002 [*] Use `__name__` with `logging.getLogger()`
|
= help: Replace with `name`
Suggested fix
Unsafe fix
8 8 | logging.getLogger(name="custom")
9 9 |
10 10 | # LOG002
@ -31,7 +31,7 @@ LOG002.py:12:24: LOG002 [*] Use `__name__` with `logging.getLogger()`
|
= help: Replace with `name`
Suggested fix
Unsafe fix
9 9 |
10 10 | # LOG002
11 11 | getLogger(__file__)
@ -51,7 +51,7 @@ LOG002.py:14:19: LOG002 [*] Use `__name__` with `logging.getLogger()`
|
= help: Replace with `name`
Suggested fix
Unsafe fix
11 11 | getLogger(__file__)
12 12 | logging.getLogger(name=__file__)
13 13 |
@ -69,7 +69,7 @@ LOG002.py:15:16: LOG002 [*] Use `__name__` with `logging.getLogger()`
|
= help: Replace with `name`
Suggested fix
Unsafe fix
12 12 | logging.getLogger(name=__file__)
13 13 |
14 14 | logging.getLogger(__cached__)

View File

@ -11,7 +11,7 @@ LOG009.py:3:1: LOG009 [*] Use of undocumented `logging.WARN` constant
|
= help: Replace `logging.WARN` with `logging.WARNING`
Suggested fix
Unsafe fix
1 1 | import logging
2 2 |
3 |-logging.WARN # LOG009
@ -30,7 +30,7 @@ LOG009.py:8:1: LOG009 [*] Use of undocumented `logging.WARN` constant
|
= help: Replace `logging.WARN` with `logging.WARNING`
Suggested fix
Unsafe fix
5 5 |
6 6 | from logging import WARN, WARNING
7 7 |

View File

@ -197,7 +197,7 @@ pub(crate) fn logging_call(checker: &mut Checker, call: &ast::ExprCall) {
) {
let mut diagnostic = Diagnostic::new(LoggingWarn, range);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
"warning".to_string(),
range,
)));

View File

@ -82,7 +82,7 @@ pub(crate) fn duplicate_class_field_definition(checker: &mut Checker, body: &[St
if checker.patch(diagnostic.kind.rule()) {
let edit =
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
diagnostic.set_fix(Fix::suggested(edit).isolate(Checker::isolation(
diagnostic.set_fix(Fix::automatic_unsafe(edit).isolate(Checker::isolation(
checker.semantic().current_statement_id(),
)));
}

View File

@ -196,7 +196,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
range: TextRange::default(),
});
let bool_op = node;
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
checker.generator().expr(&bool_op),
expr.range(),
)));

View File

@ -66,7 +66,7 @@ pub(crate) fn reimplemented_list_builtin(checker: &mut Checker, expr: &ExprLambd
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, expr.range());
if checker.patch(diagnostic.kind.rule()) {
if checker.semantic().is_builtin("list") {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
"list".to_string(),
expr.range(),
)));

View File

@ -70,7 +70,7 @@ pub(crate) fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
} else {
fix::edits::delete_stmt(stmt, None, checker.locator(), checker.indexer())
};
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
diagnostic.set_fix(Fix::automatic_safe(edit).isolate(Checker::isolation(
checker.semantic().current_statement_id(),
)));
}

View File

@ -86,7 +86,7 @@ pub(crate) fn unnecessary_range_start(checker: &mut Checker, call: &ast::ExprCal
Parentheses::Preserve,
checker.locator().contents(),
)
.map(Fix::automatic)
.map(Fix::automatic_safe)
});
}
checker.diagnostics.push(diagnostic);

View File

@ -12,7 +12,7 @@ PIE794.py:4:5: PIE794 [*] Class field `name` is defined multiple times
|
= help: Remove duplicate field definition for `name`
Suggested fix
Unsafe fix
1 1 | class Foo(BaseModel):
2 2 | name = StringField()
3 3 | # ....
@ -32,7 +32,7 @@ PIE794.py:13:5: PIE794 [*] Class field `name` is defined multiple times
|
= help: Remove duplicate field definition for `name`
Suggested fix
Unsafe fix
10 10 | class Foo(BaseModel):
11 11 | name: str = StringField()
12 12 | # ....
@ -50,7 +50,7 @@ PIE794.py:23:5: PIE794 [*] Class field `bar` is defined multiple times
|
= help: Remove duplicate field definition for `bar`
Suggested fix
Unsafe fix
20 20 | bar: str = StringField()
21 21 | foo: bool = BooleanField()
22 22 | # ...
@ -68,7 +68,7 @@ PIE794.py:40:5: PIE794 [*] Class field `bar` is defined multiple times
|
= help: Remove duplicate field definition for `bar`
Suggested fix
Unsafe fix
37 37 | bar: str = StringField()
38 38 | foo: bool = BooleanField()
39 39 | # ...

View File

@ -11,7 +11,7 @@ PIE810.py:2:1: PIE810 [*] Call `startswith` once with a `tuple`
|
= help: Merge into a single `startswith` call
Suggested fix
Unsafe fix
1 1 | # error
2 |-obj.startswith("foo") or obj.startswith("bar")
2 |+obj.startswith(("foo", "bar"))
@ -30,7 +30,7 @@ PIE810.py:4:1: PIE810 [*] Call `endswith` once with a `tuple`
|
= help: Merge into a single `endswith` call
Suggested fix
Unsafe fix
1 1 | # error
2 2 | obj.startswith("foo") or obj.startswith("bar")
3 3 | # error
@ -51,7 +51,7 @@ PIE810.py:6:1: PIE810 [*] Call `startswith` once with a `tuple`
|
= help: Merge into a single `startswith` call
Suggested fix
Unsafe fix
3 3 | # error
4 4 | obj.endswith("foo") or obj.endswith("bar")
5 5 | # error
@ -72,7 +72,7 @@ PIE810.py:8:1: PIE810 [*] Call `startswith` once with a `tuple`
|
= help: Merge into a single `startswith` call
Suggested fix
Unsafe fix
5 5 | # error
6 6 | obj.startswith(foo) or obj.startswith(bar)
7 7 | # error
@ -93,7 +93,7 @@ PIE810.py:10:1: PIE810 [*] Call `startswith` once with a `tuple`
|
= help: Merge into a single `startswith` call
Suggested fix
Unsafe fix
7 7 | # error
8 8 | obj.startswith(foo) or obj.startswith("foo")
9 9 | # error

View File

@ -81,7 +81,7 @@ pub(crate) fn any_eq_ne_annotation(checker: &mut Checker, name: &str, parameters
if checker.patch(diagnostic.kind.rule()) {
// Ex) `def __eq__(self, obj: Any): ...`
if checker.semantic().is_builtin("object") {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
"object".to_string(),
annotation.range(),
)));

View File

@ -72,7 +72,7 @@ pub(crate) fn duplicate_union_member<'a>(checker: &mut Checker, expr: &'a Expr)
if let Some(parent @ Expr::BinOp(ast::ExprBinOp { left, right, .. })) = parent {
// Replace the parent with its non-duplicate child.
let child = if expr == left.as_ref() { right } else { left };
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
checker.locator().slice(child.as_ref()).to_string(),
parent.range(),
)));

View File

@ -66,7 +66,7 @@ pub(crate) fn ellipsis_in_non_empty_class_body(checker: &mut Checker, body: &[St
if checker.patch(diagnostic.kind.rule()) {
let edit =
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
diagnostic.set_fix(Fix::automatic_safe(edit).isolate(Checker::isolation(
checker.semantic().current_statement_id(),
)));
}

View File

@ -177,7 +177,7 @@ fn check_short_args_list(checker: &mut Checker, parameters: &Parameters, func_ki
if checker.patch(diagnostic.kind.rule()) {
if checker.semantic().is_builtin("object") {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_safe(Edit::range_replacement(
"object".to_string(),
annotation.range(),
)));

View File

@ -70,7 +70,7 @@ pub(crate) fn non_empty_stub_body(checker: &mut Checker, body: &[Stmt]) {
let mut diagnostic = Diagnostic::new(NonEmptyStubBody, stmt.range());
if checker.patch(Rule::NonEmptyStubBody) {
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
format!("..."),
stmt.range(),
)));

View File

@ -51,7 +51,7 @@ pub(crate) fn numeric_literal_too_long(checker: &mut Checker, expr: &Expr) {
let mut diagnostic = Diagnostic::new(NumericLiteralTooLong, expr.range());
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic_unsafe(Edit::range_replacement(
"...".to_string(),
expr.range(),
)));

Some files were not shown because too many files have changed in this diff Show More