mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Remove preview gating for newly-added stable fixes (#9681)
## Summary At present, our versioning policy forbids the addition of safe fixes to stable rules outside of a minor release, so we've accumulated a bunch of new fixes that are behind `--preview`, and can be ungated in v0.2.0. To find these, I just grepped for `preview.is_enabled()` and identified all such cases. I then audited the `preview_rules` test fixtures and removed any tests that existed only to test this autofix behavior. # Conflicts: # crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM114_SIM114.py.snap # crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM114_SIM114.py.snap
This commit is contained in:
parent
7962bca40a
commit
0f674d1d90
94 changed files with 1827 additions and 2704 deletions
|
@ -256,7 +256,6 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
|
|||
diagnostic.set_parent(range.start());
|
||||
}
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
if let Some(import) = binding.as_any_import() {
|
||||
if let Some(source) = binding.source {
|
||||
diagnostic.try_set_fix(|| {
|
||||
|
@ -276,7 +275,6 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ mod tests {
|
|||
|
||||
use crate::assert_messages;
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::types::PreviewMode;
|
||||
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
|
||||
|
@ -71,24 +71,6 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::DuplicateValue, Path::new("B033.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
"preview__{}_{}",
|
||||
rule_code.noqa_code(),
|
||||
path.to_string_lossy()
|
||||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_bugbear").join(path).as_path(),
|
||||
&LinterSettings {
|
||||
preview: PreviewMode::Enabled,
|
||||
..LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zip_without_explicit_strict() -> Result<()> {
|
||||
let snapshot = "B905.py";
|
||||
|
|
|
@ -61,11 +61,9 @@ pub(crate) fn duplicate_value(checker: &mut Checker, set: &ast::ExprSet) {
|
|||
elt.range(),
|
||||
);
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
diagnostic.try_set_fix(|| {
|
||||
remove_member(set, index, checker.locator().contents()).map(Fix::safe_edit)
|
||||
});
|
||||
}
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
|
||||
---
|
||||
B033.py:4:35: B033 Sets should not contain duplicate item `"value1"`
|
||||
B033.py:4:35: B033 [*] Sets should not contain duplicate item `"value1"`
|
||||
|
|
||||
2 | # Errors.
|
||||
3 | ###
|
||||
|
@ -12,7 +12,17 @@ B033.py:4:35: B033 Sets should not contain duplicate item `"value1"`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
B033.py:5:21: B033 Sets should not contain duplicate item `1`
|
||||
ℹ Safe fix
|
||||
1 1 | ###
|
||||
2 2 | # Errors.
|
||||
3 3 | ###
|
||||
4 |-incorrect_set = {"value1", 23, 5, "value1"}
|
||||
4 |+incorrect_set = {"value1", 23, 5}
|
||||
5 5 | incorrect_set = {1, 1, 2}
|
||||
6 6 | incorrect_set_multiline = {
|
||||
7 7 | "value1",
|
||||
|
||||
B033.py:5:21: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
3 | ###
|
||||
4 | incorrect_set = {"value1", 23, 5, "value1"}
|
||||
|
@ -23,7 +33,17 @@ B033.py:5:21: B033 Sets should not contain duplicate item `1`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
B033.py:10:5: B033 Sets should not contain duplicate item `"value1"`
|
||||
ℹ Safe fix
|
||||
2 2 | # Errors.
|
||||
3 3 | ###
|
||||
4 4 | incorrect_set = {"value1", 23, 5, "value1"}
|
||||
5 |-incorrect_set = {1, 1, 2}
|
||||
5 |+incorrect_set = {1, 2}
|
||||
6 6 | incorrect_set_multiline = {
|
||||
7 7 | "value1",
|
||||
8 8 | 23,
|
||||
|
||||
B033.py:10:5: B033 [*] Sets should not contain duplicate item `"value1"`
|
||||
|
|
||||
8 | 23,
|
||||
9 | 5,
|
||||
|
@ -34,7 +54,16 @@ B033.py:10:5: B033 Sets should not contain duplicate item `"value1"`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
B033.py:13:21: B033 Sets should not contain duplicate item `1`
|
||||
ℹ Safe fix
|
||||
7 7 | "value1",
|
||||
8 8 | 23,
|
||||
9 9 | 5,
|
||||
10 |- "value1",
|
||||
11 10 | # B033
|
||||
12 11 | }
|
||||
13 12 | incorrect_set = {1, 1}
|
||||
|
||||
B033.py:13:21: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
11 | # B033
|
||||
12 | }
|
||||
|
@ -45,7 +74,17 @@ B033.py:13:21: B033 Sets should not contain duplicate item `1`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
B033.py:14:21: B033 Sets should not contain duplicate item `1`
|
||||
ℹ Safe fix
|
||||
10 10 | "value1",
|
||||
11 11 | # B033
|
||||
12 12 | }
|
||||
13 |-incorrect_set = {1, 1}
|
||||
13 |+incorrect_set = {1}
|
||||
14 14 | incorrect_set = {1, 1,}
|
||||
15 15 | incorrect_set = {0, 1, 1,}
|
||||
16 16 | incorrect_set = {0, 1, 1}
|
||||
|
||||
B033.py:14:21: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
12 | }
|
||||
13 | incorrect_set = {1, 1}
|
||||
|
@ -56,7 +95,17 @@ B033.py:14:21: B033 Sets should not contain duplicate item `1`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
B033.py:15:24: B033 Sets should not contain duplicate item `1`
|
||||
ℹ Safe fix
|
||||
11 11 | # B033
|
||||
12 12 | }
|
||||
13 13 | incorrect_set = {1, 1}
|
||||
14 |-incorrect_set = {1, 1,}
|
||||
14 |+incorrect_set = {1,}
|
||||
15 15 | incorrect_set = {0, 1, 1,}
|
||||
16 16 | incorrect_set = {0, 1, 1}
|
||||
17 17 | incorrect_set = {
|
||||
|
||||
B033.py:15:24: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
13 | incorrect_set = {1, 1}
|
||||
14 | incorrect_set = {1, 1,}
|
||||
|
@ -67,7 +116,17 @@ B033.py:15:24: B033 Sets should not contain duplicate item `1`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
B033.py:16:24: B033 Sets should not contain duplicate item `1`
|
||||
ℹ Safe fix
|
||||
12 12 | }
|
||||
13 13 | incorrect_set = {1, 1}
|
||||
14 14 | incorrect_set = {1, 1,}
|
||||
15 |-incorrect_set = {0, 1, 1,}
|
||||
15 |+incorrect_set = {0, 1,}
|
||||
16 16 | incorrect_set = {0, 1, 1}
|
||||
17 17 | incorrect_set = {
|
||||
18 18 | 0,
|
||||
|
||||
B033.py:16:24: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
14 | incorrect_set = {1, 1,}
|
||||
15 | incorrect_set = {0, 1, 1,}
|
||||
|
@ -78,7 +137,17 @@ B033.py:16:24: B033 Sets should not contain duplicate item `1`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
B033.py:20:5: B033 Sets should not contain duplicate item `1`
|
||||
ℹ Safe fix
|
||||
13 13 | incorrect_set = {1, 1}
|
||||
14 14 | incorrect_set = {1, 1,}
|
||||
15 15 | incorrect_set = {0, 1, 1,}
|
||||
16 |-incorrect_set = {0, 1, 1}
|
||||
16 |+incorrect_set = {0, 1}
|
||||
17 17 | incorrect_set = {
|
||||
18 18 | 0,
|
||||
19 19 | 1,
|
||||
|
||||
B033.py:20:5: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
18 | 0,
|
||||
19 | 1,
|
||||
|
@ -88,4 +157,13 @@ B033.py:20:5: B033 Sets should not contain duplicate item `1`
|
|||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
17 17 | incorrect_set = {
|
||||
18 18 | 0,
|
||||
19 19 | 1,
|
||||
20 |- 1,
|
||||
21 20 | }
|
||||
22 21 |
|
||||
23 22 | ###
|
||||
|
||||
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
|
||||
---
|
||||
B033.py:4:35: B033 [*] Sets should not contain duplicate item `"value1"`
|
||||
|
|
||||
2 | # Errors.
|
||||
3 | ###
|
||||
4 | incorrect_set = {"value1", 23, 5, "value1"}
|
||||
| ^^^^^^^^ B033
|
||||
5 | incorrect_set = {1, 1, 2}
|
||||
6 | incorrect_set_multiline = {
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | ###
|
||||
2 2 | # Errors.
|
||||
3 3 | ###
|
||||
4 |-incorrect_set = {"value1", 23, 5, "value1"}
|
||||
4 |+incorrect_set = {"value1", 23, 5}
|
||||
5 5 | incorrect_set = {1, 1, 2}
|
||||
6 6 | incorrect_set_multiline = {
|
||||
7 7 | "value1",
|
||||
|
||||
B033.py:5:21: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
3 | ###
|
||||
4 | incorrect_set = {"value1", 23, 5, "value1"}
|
||||
5 | incorrect_set = {1, 1, 2}
|
||||
| ^ B033
|
||||
6 | incorrect_set_multiline = {
|
||||
7 | "value1",
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 | # Errors.
|
||||
3 3 | ###
|
||||
4 4 | incorrect_set = {"value1", 23, 5, "value1"}
|
||||
5 |-incorrect_set = {1, 1, 2}
|
||||
5 |+incorrect_set = {1, 2}
|
||||
6 6 | incorrect_set_multiline = {
|
||||
7 7 | "value1",
|
||||
8 8 | 23,
|
||||
|
||||
B033.py:10:5: B033 [*] Sets should not contain duplicate item `"value1"`
|
||||
|
|
||||
8 | 23,
|
||||
9 | 5,
|
||||
10 | "value1",
|
||||
| ^^^^^^^^ B033
|
||||
11 | # B033
|
||||
12 | }
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
7 7 | "value1",
|
||||
8 8 | 23,
|
||||
9 9 | 5,
|
||||
10 |- "value1",
|
||||
11 10 | # B033
|
||||
12 11 | }
|
||||
13 12 | incorrect_set = {1, 1}
|
||||
|
||||
B033.py:13:21: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
11 | # B033
|
||||
12 | }
|
||||
13 | incorrect_set = {1, 1}
|
||||
| ^ B033
|
||||
14 | incorrect_set = {1, 1,}
|
||||
15 | incorrect_set = {0, 1, 1,}
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
10 10 | "value1",
|
||||
11 11 | # B033
|
||||
12 12 | }
|
||||
13 |-incorrect_set = {1, 1}
|
||||
13 |+incorrect_set = {1}
|
||||
14 14 | incorrect_set = {1, 1,}
|
||||
15 15 | incorrect_set = {0, 1, 1,}
|
||||
16 16 | incorrect_set = {0, 1, 1}
|
||||
|
||||
B033.py:14:21: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
12 | }
|
||||
13 | incorrect_set = {1, 1}
|
||||
14 | incorrect_set = {1, 1,}
|
||||
| ^ B033
|
||||
15 | incorrect_set = {0, 1, 1,}
|
||||
16 | incorrect_set = {0, 1, 1}
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
11 11 | # B033
|
||||
12 12 | }
|
||||
13 13 | incorrect_set = {1, 1}
|
||||
14 |-incorrect_set = {1, 1,}
|
||||
14 |+incorrect_set = {1,}
|
||||
15 15 | incorrect_set = {0, 1, 1,}
|
||||
16 16 | incorrect_set = {0, 1, 1}
|
||||
17 17 | incorrect_set = {
|
||||
|
||||
B033.py:15:24: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
13 | incorrect_set = {1, 1}
|
||||
14 | incorrect_set = {1, 1,}
|
||||
15 | incorrect_set = {0, 1, 1,}
|
||||
| ^ B033
|
||||
16 | incorrect_set = {0, 1, 1}
|
||||
17 | incorrect_set = {
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
12 12 | }
|
||||
13 13 | incorrect_set = {1, 1}
|
||||
14 14 | incorrect_set = {1, 1,}
|
||||
15 |-incorrect_set = {0, 1, 1,}
|
||||
15 |+incorrect_set = {0, 1,}
|
||||
16 16 | incorrect_set = {0, 1, 1}
|
||||
17 17 | incorrect_set = {
|
||||
18 18 | 0,
|
||||
|
||||
B033.py:16:24: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
14 | incorrect_set = {1, 1,}
|
||||
15 | incorrect_set = {0, 1, 1,}
|
||||
16 | incorrect_set = {0, 1, 1}
|
||||
| ^ B033
|
||||
17 | incorrect_set = {
|
||||
18 | 0,
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
13 13 | incorrect_set = {1, 1}
|
||||
14 14 | incorrect_set = {1, 1,}
|
||||
15 15 | incorrect_set = {0, 1, 1,}
|
||||
16 |-incorrect_set = {0, 1, 1}
|
||||
16 |+incorrect_set = {0, 1}
|
||||
17 17 | incorrect_set = {
|
||||
18 18 | 0,
|
||||
19 19 | 1,
|
||||
|
||||
B033.py:20:5: B033 [*] Sets should not contain duplicate item `1`
|
||||
|
|
||||
18 | 0,
|
||||
19 | 1,
|
||||
20 | 1,
|
||||
| ^ B033
|
||||
21 | }
|
||||
|
|
||||
= help: Remove duplicate item
|
||||
|
||||
ℹ Safe fix
|
||||
17 17 | incorrect_set = {
|
||||
18 18 | 0,
|
||||
19 19 | 1,
|
||||
20 |- 1,
|
||||
21 20 | }
|
||||
22 21 |
|
||||
23 22 | ###
|
||||
|
||||
|
|
@ -33,7 +33,6 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test_case(Rule::UnnecessaryPlaceholder, Path::new("PIE790.py"))]
|
||||
#[test_case(Rule::UnnecessarySpread, Path::new("PIE800.py"))]
|
||||
#[test_case(Rule::ReimplementedContainerBuiltin, Path::new("PIE807.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
|
|
|
@ -55,11 +55,9 @@ pub(crate) fn unnecessary_spread(checker: &mut Checker, dict: &ast::ExprDict) {
|
|||
// inside a dict.
|
||||
if let Expr::Dict(inner) = value {
|
||||
let mut diagnostic = Diagnostic::new(UnnecessarySpread, value.range());
|
||||
if checker.settings.preview.is_enabled() {
|
||||
if let Some(fix) = unnecessary_spread_fix(inner, prev_end, checker.locator()) {
|
||||
diagnostic.set_fix(fix);
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_pie/mod.rs
|
||||
---
|
||||
PIE800.py:1:14: PIE800 Unnecessary spread `**`
|
||||
PIE800.py:1:14: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
1 | {"foo": 1, **{"bar": 1}} # PIE800
|
||||
| ^^^^^^^^^^ PIE800
|
||||
|
@ -10,7 +10,14 @@ PIE800.py:1:14: PIE800 Unnecessary spread `**`
|
|||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
PIE800.py:3:4: PIE800 Unnecessary spread `**`
|
||||
ℹ Safe fix
|
||||
1 |-{"foo": 1, **{"bar": 1}} # PIE800
|
||||
1 |+{"foo": 1, "bar": 1} # PIE800
|
||||
2 2 |
|
||||
3 3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
4 4 |
|
||||
|
||||
PIE800.py:3:4: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
1 | {"foo": 1, **{"bar": 1}} # PIE800
|
||||
2 |
|
||||
|
@ -21,7 +28,16 @@ PIE800.py:3:4: PIE800 Unnecessary spread `**`
|
|||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
PIE800.py:5:15: PIE800 Unnecessary spread `**`
|
||||
ℹ Safe fix
|
||||
1 1 | {"foo": 1, **{"bar": 1}} # PIE800
|
||||
2 2 |
|
||||
3 |-{**{"bar": 10}, "a": "b"} # PIE800
|
||||
3 |+{"bar": 10, "a": "b"} # PIE800
|
||||
4 4 |
|
||||
5 5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
6 6 |
|
||||
|
||||
PIE800.py:5:15: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
4 |
|
||||
|
@ -32,7 +48,17 @@ PIE800.py:5:15: PIE800 Unnecessary spread `**`
|
|||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
PIE800.py:7:11: PIE800 Unnecessary spread `**`
|
||||
ℹ Safe fix
|
||||
2 2 |
|
||||
3 3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
4 4 |
|
||||
5 |-foo({**foo, **{"bar": True}}) # PIE800
|
||||
5 |+foo({**foo, "bar": True}) # PIE800
|
||||
6 6 |
|
||||
7 7 | {**foo, **{"bar": 10}} # PIE800
|
||||
8 8 |
|
||||
|
||||
PIE800.py:7:11: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
6 |
|
||||
|
@ -43,7 +69,17 @@ PIE800.py:7:11: PIE800 Unnecessary spread `**`
|
|||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
PIE800.py:12:7: PIE800 Unnecessary spread `**`
|
||||
ℹ Safe fix
|
||||
4 4 |
|
||||
5 5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
6 6 |
|
||||
7 |-{**foo, **{"bar": 10}} # PIE800
|
||||
7 |+{**foo, "bar": 10} # PIE800
|
||||
8 8 |
|
||||
9 9 | { # PIE800
|
||||
10 10 | "a": "b",
|
||||
|
||||
PIE800.py:12:7: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
10 | "a": "b",
|
||||
11 | # Preserve
|
||||
|
@ -58,7 +94,23 @@ PIE800.py:12:7: PIE800 Unnecessary spread `**`
|
|||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
PIE800.py:19:19: PIE800 Unnecessary spread `**`
|
||||
ℹ Safe fix
|
||||
9 9 | { # PIE800
|
||||
10 10 | "a": "b",
|
||||
11 11 | # Preserve
|
||||
12 |- **{
|
||||
12 |+
|
||||
13 13 | # all
|
||||
14 |- "bar": 10, # the
|
||||
14 |+ "bar": 10 # the
|
||||
15 15 | # comments
|
||||
16 |- },
|
||||
16 |+ ,
|
||||
17 17 | }
|
||||
18 18 |
|
||||
19 19 | {**foo, **buzz, **{bar: 10}} # PIE800
|
||||
|
||||
PIE800.py:19:19: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
17 | }
|
||||
18 |
|
||||
|
@ -69,4 +121,14 @@ PIE800.py:19:19: PIE800 Unnecessary spread `**`
|
|||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
ℹ Safe fix
|
||||
16 16 | },
|
||||
17 17 | }
|
||||
18 18 |
|
||||
19 |-{**foo, **buzz, **{bar: 10}} # PIE800
|
||||
19 |+{**foo, **buzz, bar: 10} # PIE800
|
||||
20 20 |
|
||||
21 21 | {**foo, "bar": True } # OK
|
||||
22 22 |
|
||||
|
||||
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_pie/mod.rs
|
||||
---
|
||||
PIE800.py:1:14: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
1 | {"foo": 1, **{"bar": 1}} # PIE800
|
||||
| ^^^^^^^^^^ PIE800
|
||||
2 |
|
||||
3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
ℹ Safe fix
|
||||
1 |-{"foo": 1, **{"bar": 1}} # PIE800
|
||||
1 |+{"foo": 1, "bar": 1} # PIE800
|
||||
2 2 |
|
||||
3 3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
4 4 |
|
||||
|
||||
PIE800.py:3:4: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
1 | {"foo": 1, **{"bar": 1}} # PIE800
|
||||
2 |
|
||||
3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
| ^^^^^^^^^^^ PIE800
|
||||
4 |
|
||||
5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | {"foo": 1, **{"bar": 1}} # PIE800
|
||||
2 2 |
|
||||
3 |-{**{"bar": 10}, "a": "b"} # PIE800
|
||||
3 |+{"bar": 10, "a": "b"} # PIE800
|
||||
4 4 |
|
||||
5 5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
6 6 |
|
||||
|
||||
PIE800.py:5:15: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
4 |
|
||||
5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
| ^^^^^^^^^^^^^ PIE800
|
||||
6 |
|
||||
7 | {**foo, **{"bar": 10}} # PIE800
|
||||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 |
|
||||
3 3 | {**{"bar": 10}, "a": "b"} # PIE800
|
||||
4 4 |
|
||||
5 |-foo({**foo, **{"bar": True}}) # PIE800
|
||||
5 |+foo({**foo, "bar": True}) # PIE800
|
||||
6 6 |
|
||||
7 7 | {**foo, **{"bar": 10}} # PIE800
|
||||
8 8 |
|
||||
|
||||
PIE800.py:7:11: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
6 |
|
||||
7 | {**foo, **{"bar": 10}} # PIE800
|
||||
| ^^^^^^^^^^^ PIE800
|
||||
8 |
|
||||
9 | { # PIE800
|
||||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
ℹ Safe fix
|
||||
4 4 |
|
||||
5 5 | foo({**foo, **{"bar": True}}) # PIE800
|
||||
6 6 |
|
||||
7 |-{**foo, **{"bar": 10}} # PIE800
|
||||
7 |+{**foo, "bar": 10} # PIE800
|
||||
8 8 |
|
||||
9 9 | { # PIE800
|
||||
10 10 | "a": "b",
|
||||
|
||||
PIE800.py:12:7: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
10 | "a": "b",
|
||||
11 | # Preserve
|
||||
12 | **{
|
||||
| _______^
|
||||
13 | | # all
|
||||
14 | | "bar": 10, # the
|
||||
15 | | # comments
|
||||
16 | | },
|
||||
| |_____^ PIE800
|
||||
17 | }
|
||||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
ℹ Safe fix
|
||||
9 9 | { # PIE800
|
||||
10 10 | "a": "b",
|
||||
11 11 | # Preserve
|
||||
12 |- **{
|
||||
12 |+
|
||||
13 13 | # all
|
||||
14 |- "bar": 10, # the
|
||||
14 |+ "bar": 10 # the
|
||||
15 15 | # comments
|
||||
16 |- },
|
||||
16 |+ ,
|
||||
17 17 | }
|
||||
18 18 |
|
||||
19 19 | {**foo, **buzz, **{bar: 10}} # PIE800
|
||||
|
||||
PIE800.py:19:19: PIE800 [*] Unnecessary spread `**`
|
||||
|
|
||||
17 | }
|
||||
18 |
|
||||
19 | {**foo, **buzz, **{bar: 10}} # PIE800
|
||||
| ^^^^^^^^^ PIE800
|
||||
20 |
|
||||
21 | {**foo, "bar": True } # OK
|
||||
|
|
||||
= help: Remove unnecessary dict
|
||||
|
||||
ℹ Safe fix
|
||||
16 16 | },
|
||||
17 17 | }
|
||||
18 18 |
|
||||
19 |-{**foo, **buzz, **{bar: 10}} # PIE800
|
||||
19 |+{**foo, **buzz, bar: 10} # PIE800
|
||||
20 20 |
|
||||
21 21 | {**foo, "bar": True } # OK
|
||||
22 22 |
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp
|
|||
expr.range(),
|
||||
);
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
diagnostic.set_fix({
|
||||
let literal = Expr::Subscript(ast::ExprSubscript {
|
||||
value: Box::new(literal_subscript.clone()),
|
||||
slice: Box::new(Expr::Tuple(ast::ExprTuple {
|
||||
|
@ -130,10 +130,10 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp
|
|||
|
||||
if other_exprs.is_empty() {
|
||||
// if the union is only literals, we just replace the whole thing with a single literal
|
||||
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
|
||||
Fix::safe_edit(Edit::range_replacement(
|
||||
checker.generator().expr(&literal),
|
||||
expr.range(),
|
||||
)));
|
||||
))
|
||||
} else {
|
||||
let elts: Vec<Expr> = std::iter::once(literal)
|
||||
.chain(other_exprs.into_iter().cloned())
|
||||
|
@ -156,12 +156,9 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp
|
|||
checker.generator().expr(&pep_604_union(&elts))
|
||||
};
|
||||
|
||||
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
)));
|
||||
}
|
||||
Fix::safe_edit(Edit::range_replacement(content, expr.range()))
|
||||
}
|
||||
});
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
|
||||
---
|
||||
PYI030.py:9:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
PYI030.py:9:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
8 | # Should emit for duplicate field types.
|
||||
9 | field2: Literal[1] | Literal[2] # Error
|
||||
|
@ -11,7 +11,17 @@ PYI030.py:9:9: PYI030 Multiple literal members in a union. Use a single literal,
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:12:17: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
6 6 | field1: Literal[1] # OK
|
||||
7 7 |
|
||||
8 8 | # Should emit for duplicate field types.
|
||||
9 |-field2: Literal[1] | Literal[2] # Error
|
||||
9 |+field2: Literal[1, 2] # Error
|
||||
10 10 |
|
||||
11 11 | # Should emit for union types in arguments.
|
||||
12 12 | def func1(arg1: Literal[1] | Literal[2]): # Error
|
||||
|
||||
PYI030.py:12:17: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
11 | # Should emit for union types in arguments.
|
||||
12 | def func1(arg1: Literal[1] | Literal[2]): # Error
|
||||
|
@ -20,7 +30,17 @@ PYI030.py:12:17: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:17:16: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
9 9 | field2: Literal[1] | Literal[2] # Error
|
||||
10 10 |
|
||||
11 11 | # Should emit for union types in arguments.
|
||||
12 |-def func1(arg1: Literal[1] | Literal[2]): # Error
|
||||
12 |+def func1(arg1: Literal[1, 2]): # Error
|
||||
13 13 | print(arg1)
|
||||
14 14 |
|
||||
15 15 |
|
||||
|
||||
PYI030.py:17:16: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
16 | # Should emit for unions in return types.
|
||||
17 | def func2() -> Literal[1] | Literal[2]: # Error
|
||||
|
@ -29,7 +49,17 @@ PYI030.py:17:16: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:22:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
14 14 |
|
||||
15 15 |
|
||||
16 16 | # Should emit for unions in return types.
|
||||
17 |-def func2() -> Literal[1] | Literal[2]: # Error
|
||||
17 |+def func2() -> Literal[1, 2]: # Error
|
||||
18 18 | return "my Literal[1]ing"
|
||||
19 19 |
|
||||
20 20 |
|
||||
|
||||
PYI030.py:22:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
|
@ -39,7 +69,17 @@ PYI030.py:22:9: PYI030 Multiple literal members in a union. Use a single literal
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:23:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
19 19 |
|
||||
20 20 |
|
||||
21 21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 |-field3: Literal[1] | Literal[2] | str # Error
|
||||
22 |+field3: Literal[1, 2] | str # Error
|
||||
23 23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
|
||||
PYI030.py:23:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
|
@ -50,7 +90,17 @@ PYI030.py:23:9: PYI030 Multiple literal members in a union. Use a single literal
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:24:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
20 20 |
|
||||
21 21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 |-field4: str | Literal[1] | Literal[2] # Error
|
||||
23 |+field4: Literal[1, 2] | str # Error
|
||||
24 24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
26 26 |
|
||||
|
||||
PYI030.py:24:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
|
@ -60,7 +110,17 @@ PYI030.py:24:9: PYI030 Multiple literal members in a union. Use a single literal
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:25:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
21 21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 |-field5: Literal[1] | str | Literal[2] # Error
|
||||
24 |+field5: Literal[1, 2] | str # Error
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
26 26 |
|
||||
27 27 | # Should emit for non-type unions.
|
||||
|
||||
PYI030.py:25:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
|
@ -71,7 +131,17 @@ PYI030.py:25:9: PYI030 Multiple literal members in a union. Use a single literal
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:28:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
22 22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
25 |-field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
25 |+field6: Literal[1, 2] | bool | str # Error
|
||||
26 26 |
|
||||
27 27 | # Should emit for non-type unions.
|
||||
28 28 | field7 = Literal[1] | Literal[2] # Error
|
||||
|
||||
PYI030.py:28:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
27 | # Should emit for non-type unions.
|
||||
28 | field7 = Literal[1] | Literal[2] # Error
|
||||
|
@ -81,7 +151,17 @@ PYI030.py:28:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:31:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
26 26 |
|
||||
27 27 | # Should emit for non-type unions.
|
||||
28 |-field7 = Literal[1] | Literal[2] # Error
|
||||
28 |+field7 = Literal[1, 2] # Error
|
||||
29 29 |
|
||||
30 30 | # Should emit for parenthesized unions.
|
||||
31 31 | field8: Literal[1] | (Literal[2] | str) # Error
|
||||
|
||||
PYI030.py:31:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
30 | # Should emit for parenthesized unions.
|
||||
31 | field8: Literal[1] | (Literal[2] | str) # Error
|
||||
|
@ -91,7 +171,17 @@ PYI030.py:31:9: PYI030 Multiple literal members in a union. Use a single literal
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:34:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
28 28 | field7 = Literal[1] | Literal[2] # Error
|
||||
29 29 |
|
||||
30 30 | # Should emit for parenthesized unions.
|
||||
31 |-field8: Literal[1] | (Literal[2] | str) # Error
|
||||
31 |+field8: Literal[1, 2] | str # Error
|
||||
32 32 |
|
||||
33 33 | # Should handle user parentheses when fixing.
|
||||
34 34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
|
||||
PYI030.py:34:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
33 | # Should handle user parentheses when fixing.
|
||||
34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
|
@ -100,7 +190,17 @@ PYI030.py:34:9: PYI030 Multiple literal members in a union. Use a single literal
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:35:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
31 31 | field8: Literal[1] | (Literal[2] | str) # Error
|
||||
32 32 |
|
||||
33 33 | # Should handle user parentheses when fixing.
|
||||
34 |-field9: Literal[1] | (Literal[2] | str) # Error
|
||||
34 |+field9: Literal[1, 2] | str # Error
|
||||
35 35 | field10: (Literal[1] | str) | Literal[2] # Error
|
||||
36 36 |
|
||||
37 37 | # Should emit for union in generic parent type.
|
||||
|
||||
PYI030.py:35:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
33 | # Should handle user parentheses when fixing.
|
||||
34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
|
@ -111,7 +211,17 @@ PYI030.py:35:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:38:15: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
32 32 |
|
||||
33 33 | # Should handle user parentheses when fixing.
|
||||
34 34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
35 |-field10: (Literal[1] | str) | Literal[2] # Error
|
||||
35 |+field10: Literal[1, 2] | str # Error
|
||||
36 36 |
|
||||
37 37 | # Should emit for union in generic parent type.
|
||||
38 38 | field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
|
||||
PYI030.py:38:15: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
37 | # Should emit for union in generic parent type.
|
||||
38 | field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
|
@ -121,7 +231,17 @@ PYI030.py:38:15: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:41:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
ℹ Safe fix
|
||||
35 35 | field10: (Literal[1] | str) | Literal[2] # Error
|
||||
36 36 |
|
||||
37 37 | # Should emit for union in generic parent type.
|
||||
38 |-field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
38 |+field11: dict[Literal[1, 2], str] # Error
|
||||
39 39 |
|
||||
40 40 | # Should emit for unions with more than two cases
|
||||
41 41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
|
||||
PYI030.py:41:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
|
|
||||
40 | # Should emit for unions with more than two cases
|
||||
41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
|
@ -130,7 +250,17 @@ PYI030.py:41:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:42:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
38 38 | field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
39 39 |
|
||||
40 40 | # Should emit for unions with more than two cases
|
||||
41 |-field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
41 |+field12: Literal[1, 2, 3] # Error
|
||||
42 42 | field13: Literal[1] | Literal[2] | Literal[3] | Literal[4] # Error
|
||||
43 43 |
|
||||
44 44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
|
||||
PYI030.py:42:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
40 | # Should emit for unions with more than two cases
|
||||
41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
|
@ -141,7 +271,17 @@ PYI030.py:42:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:45:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
ℹ Safe fix
|
||||
39 39 |
|
||||
40 40 | # Should emit for unions with more than two cases
|
||||
41 41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
42 |-field13: Literal[1] | Literal[2] | Literal[3] | Literal[4] # Error
|
||||
42 |+field13: Literal[1, 2, 3, 4] # Error
|
||||
43 43 |
|
||||
44 44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
45 45 | field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
|
||||
PYI030.py:45:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
|
|
||||
44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
45 | field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
|
@ -151,7 +291,17 @@ PYI030.py:45:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:48:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, "foo", True]`
|
||||
ℹ Safe fix
|
||||
42 42 | field13: Literal[1] | Literal[2] | Literal[3] | Literal[4] # Error
|
||||
43 43 |
|
||||
44 44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
45 |-field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
45 |+field14: Literal[1, 2, 3] | str # Error
|
||||
46 46 |
|
||||
47 47 | # Should emit for unions with mixed literal internal types
|
||||
48 48 | field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
|
||||
PYI030.py:48:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, "foo", True]`
|
||||
|
|
||||
47 | # Should emit for unions with mixed literal internal types
|
||||
48 | field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
|
@ -161,7 +311,17 @@ PYI030.py:48:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:51:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 1]`
|
||||
ℹ Safe fix
|
||||
45 45 | field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
46 46 |
|
||||
47 47 | # Should emit for unions with mixed literal internal types
|
||||
48 |-field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
48 |+field15: Literal[1, "foo", True] # Error
|
||||
49 49 |
|
||||
50 50 | # Shouldn't emit for duplicate field types with same value; covered by Y016
|
||||
51 51 | field16: Literal[1] | Literal[1] # OK
|
||||
|
||||
PYI030.py:51:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 1]`
|
||||
|
|
||||
50 | # Shouldn't emit for duplicate field types with same value; covered by Y016
|
||||
51 | field16: Literal[1] | Literal[1] # OK
|
||||
|
@ -171,7 +331,17 @@ PYI030.py:51:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:60:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
48 48 | field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
49 49 |
|
||||
50 50 | # Shouldn't emit for duplicate field types with same value; covered by Y016
|
||||
51 |-field16: Literal[1] | Literal[1] # OK
|
||||
51 |+field16: Literal[1, 1] # OK
|
||||
52 52 |
|
||||
53 53 | # Shouldn't emit if in new parent type
|
||||
54 54 | field17: Literal[1] | dict[Literal[2], str] # OK
|
||||
|
||||
PYI030.py:60:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
59 | # Should respect name of literal type used
|
||||
60 | field19: typing.Literal[1] | typing.Literal[2] # Error
|
||||
|
@ -181,7 +351,17 @@ PYI030.py:60:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:63:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
57 57 | field18: dict[Literal[1], Literal[2]] # OK
|
||||
58 58 |
|
||||
59 59 | # Should respect name of literal type used
|
||||
60 |-field19: typing.Literal[1] | typing.Literal[2] # Error
|
||||
60 |+field19: typing.Literal[1, 2] # Error
|
||||
61 61 |
|
||||
62 62 | # Should emit in cases with newlines
|
||||
63 63 | field20: typing.Union[
|
||||
|
||||
PYI030.py:63:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
62 | # Should emit in cases with newlines
|
||||
63 | field20: typing.Union[
|
||||
|
@ -197,7 +377,22 @@ PYI030.py:63:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:71:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
60 60 | field19: typing.Literal[1] | typing.Literal[2] # Error
|
||||
61 61 |
|
||||
62 62 | # Should emit in cases with newlines
|
||||
63 |-field20: typing.Union[
|
||||
64 |- Literal[
|
||||
65 |- 1 # test
|
||||
66 |- ],
|
||||
67 |- Literal[2],
|
||||
68 |-] # Error, newline and comment will not be emitted in message
|
||||
63 |+field20: Literal[1, 2] # Error, newline and comment will not be emitted in message
|
||||
69 64 |
|
||||
70 65 | # Should handle multiple unions with multiple members
|
||||
71 66 | field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
|
||||
PYI030.py:71:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
70 | # Should handle multiple unions with multiple members
|
||||
71 | field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
|
@ -207,7 +402,17 @@ PYI030.py:71:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:74:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
68 68 | ] # Error, newline and comment will not be emitted in message
|
||||
69 69 |
|
||||
70 70 | # Should handle multiple unions with multiple members
|
||||
71 |-field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
71 |+field21: Literal[1, 2, 3, 4] # Error
|
||||
72 72 |
|
||||
73 73 | # Should emit in cases with `typing.Union` instead of `|`
|
||||
74 74 | field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
|
||||
PYI030.py:74:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
73 | # Should emit in cases with `typing.Union` instead of `|`
|
||||
74 | field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
|
@ -217,7 +422,17 @@ PYI030.py:74:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:77:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
71 71 | field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
72 72 |
|
||||
73 73 | # Should emit in cases with `typing.Union` instead of `|`
|
||||
74 |-field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
74 |+field22: Literal[1, 2] # Error
|
||||
75 75 |
|
||||
76 76 | # Should emit in cases with `typing_extensions.Literal`
|
||||
77 77 | field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
|
||||
PYI030.py:77:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
76 | # Should emit in cases with `typing_extensions.Literal`
|
||||
77 | field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
|
@ -227,7 +442,17 @@ PYI030.py:77:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:80:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
74 74 | field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
75 75 |
|
||||
76 76 | # Should emit in cases with `typing_extensions.Literal`
|
||||
77 |-field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
77 |+field23: typing_extensions.Literal[1, 2] # Error
|
||||
78 78 |
|
||||
79 79 | # Should emit in cases with nested `typing.Union`
|
||||
80 80 | field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
|
||||
PYI030.py:80:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
79 | # Should emit in cases with nested `typing.Union`
|
||||
80 | field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
|
@ -237,7 +462,17 @@ PYI030.py:80:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:83:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
77 77 | field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
78 78 |
|
||||
79 79 | # Should emit in cases with nested `typing.Union`
|
||||
80 |-field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
80 |+field24: typing.Union[Literal[1, 2], str] # Error
|
||||
81 81 |
|
||||
82 82 | # Should emit in cases with mixed `typing.Union` and `|`
|
||||
83 83 | field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
|
||||
PYI030.py:83:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
82 | # Should emit in cases with mixed `typing.Union` and `|`
|
||||
83 | field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
|
@ -247,7 +482,17 @@ PYI030.py:83:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:86:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
80 80 | field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
81 81 |
|
||||
82 82 | # Should emit in cases with mixed `typing.Union` and `|`
|
||||
83 |-field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
83 |+field25: typing.Union[Literal[1, 2], str] # Error
|
||||
84 84 |
|
||||
85 85 | # Should emit only once in cases with multiple nested `typing.Union`
|
||||
86 86 | field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
|
||||
PYI030.py:86:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
85 | # Should emit only once in cases with multiple nested `typing.Union`
|
||||
86 | field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
|
@ -257,7 +502,17 @@ PYI030.py:86:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.py:89:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
83 83 | field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
84 84 |
|
||||
85 85 | # Should emit only once in cases with multiple nested `typing.Union`
|
||||
86 |-field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
86 |+field24: Literal[1, 2, 3, 4] # Error
|
||||
87 87 |
|
||||
88 88 | # Should use the first literal subscript attribute when fixing
|
||||
89 89 | field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||
|
||||
PYI030.py:89:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
88 | # Should use the first literal subscript attribute when fixing
|
||||
89 | field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||
|
@ -265,4 +520,11 @@ PYI030.py:89:10: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
ℹ Safe fix
|
||||
86 86 | field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
87 87 |
|
||||
88 88 | # Should use the first literal subscript attribute when fixing
|
||||
89 |-field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||
89 |+field25: typing.Union[typing_extensions.Literal[1, 2, 3, 4], str] # Error
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
|
||||
---
|
||||
PYI030.pyi:9:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
PYI030.pyi:9:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
8 | # Should emit for duplicate field types.
|
||||
9 | field2: Literal[1] | Literal[2] # Error
|
||||
|
@ -11,7 +11,17 @@ PYI030.pyi:9:9: PYI030 Multiple literal members in a union. Use a single literal
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:12:17: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
6 6 | field1: Literal[1] # OK
|
||||
7 7 |
|
||||
8 8 | # Should emit for duplicate field types.
|
||||
9 |-field2: Literal[1] | Literal[2] # Error
|
||||
9 |+field2: Literal[1, 2] # Error
|
||||
10 10 |
|
||||
11 11 | # Should emit for union types in arguments.
|
||||
12 12 | def func1(arg1: Literal[1] | Literal[2]): # Error
|
||||
|
||||
PYI030.pyi:12:17: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
11 | # Should emit for union types in arguments.
|
||||
12 | def func1(arg1: Literal[1] | Literal[2]): # Error
|
||||
|
@ -20,7 +30,17 @@ PYI030.pyi:12:17: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:17:16: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
9 9 | field2: Literal[1] | Literal[2] # Error
|
||||
10 10 |
|
||||
11 11 | # Should emit for union types in arguments.
|
||||
12 |-def func1(arg1: Literal[1] | Literal[2]): # Error
|
||||
12 |+def func1(arg1: Literal[1, 2]): # Error
|
||||
13 13 | print(arg1)
|
||||
14 14 |
|
||||
15 15 |
|
||||
|
||||
PYI030.pyi:17:16: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
16 | # Should emit for unions in return types.
|
||||
17 | def func2() -> Literal[1] | Literal[2]: # Error
|
||||
|
@ -29,7 +49,17 @@ PYI030.pyi:17:16: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:22:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
14 14 |
|
||||
15 15 |
|
||||
16 16 | # Should emit for unions in return types.
|
||||
17 |-def func2() -> Literal[1] | Literal[2]: # Error
|
||||
17 |+def func2() -> Literal[1, 2]: # Error
|
||||
18 18 | return "my Literal[1]ing"
|
||||
19 19 |
|
||||
20 20 |
|
||||
|
||||
PYI030.pyi:22:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
|
@ -39,7 +69,17 @@ PYI030.pyi:22:9: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:23:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
19 19 |
|
||||
20 20 |
|
||||
21 21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 |-field3: Literal[1] | Literal[2] | str # Error
|
||||
22 |+field3: Literal[1, 2] | str # Error
|
||||
23 23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
|
||||
PYI030.pyi:23:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
|
@ -50,7 +90,17 @@ PYI030.pyi:23:9: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:24:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
20 20 |
|
||||
21 21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 |-field4: str | Literal[1] | Literal[2] # Error
|
||||
23 |+field4: Literal[1, 2] | str # Error
|
||||
24 24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
26 26 |
|
||||
|
||||
PYI030.pyi:24:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
|
@ -60,7 +110,17 @@ PYI030.pyi:24:9: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:25:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
21 21 | # Should emit in longer unions, even if not directly adjacent.
|
||||
22 22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 |-field5: Literal[1] | str | Literal[2] # Error
|
||||
24 |+field5: Literal[1, 2] | str # Error
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
26 26 |
|
||||
27 27 | # Should emit for non-type unions.
|
||||
|
||||
PYI030.pyi:25:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
|
@ -71,7 +131,17 @@ PYI030.pyi:25:9: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:28:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
22 22 | field3: Literal[1] | Literal[2] | str # Error
|
||||
23 23 | field4: str | Literal[1] | Literal[2] # Error
|
||||
24 24 | field5: Literal[1] | str | Literal[2] # Error
|
||||
25 |-field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
25 |+field6: Literal[1, 2] | bool | str # Error
|
||||
26 26 |
|
||||
27 27 | # Should emit for non-type unions.
|
||||
28 28 | field7 = Literal[1] | Literal[2] # Error
|
||||
|
||||
PYI030.pyi:28:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
27 | # Should emit for non-type unions.
|
||||
28 | field7 = Literal[1] | Literal[2] # Error
|
||||
|
@ -81,7 +151,17 @@ PYI030.pyi:28:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:31:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
25 25 | field6: Literal[1] | bool | Literal[2] | str # Error
|
||||
26 26 |
|
||||
27 27 | # Should emit for non-type unions.
|
||||
28 |-field7 = Literal[1] | Literal[2] # Error
|
||||
28 |+field7 = Literal[1, 2] # Error
|
||||
29 29 |
|
||||
30 30 | # Should emit for parenthesized unions.
|
||||
31 31 | field8: Literal[1] | (Literal[2] | str) # Error
|
||||
|
||||
PYI030.pyi:31:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
30 | # Should emit for parenthesized unions.
|
||||
31 | field8: Literal[1] | (Literal[2] | str) # Error
|
||||
|
@ -91,7 +171,17 @@ PYI030.pyi:31:9: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:34:9: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
28 28 | field7 = Literal[1] | Literal[2] # Error
|
||||
29 29 |
|
||||
30 30 | # Should emit for parenthesized unions.
|
||||
31 |-field8: Literal[1] | (Literal[2] | str) # Error
|
||||
31 |+field8: Literal[1, 2] | str # Error
|
||||
32 32 |
|
||||
33 33 | # Should handle user parentheses when fixing.
|
||||
34 34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
|
||||
PYI030.pyi:34:9: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
33 | # Should handle user parentheses when fixing.
|
||||
34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
|
@ -100,7 +190,17 @@ PYI030.pyi:34:9: PYI030 Multiple literal members in a union. Use a single litera
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:35:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
31 31 | field8: Literal[1] | (Literal[2] | str) # Error
|
||||
32 32 |
|
||||
33 33 | # Should handle user parentheses when fixing.
|
||||
34 |-field9: Literal[1] | (Literal[2] | str) # Error
|
||||
34 |+field9: Literal[1, 2] | str # Error
|
||||
35 35 | field10: (Literal[1] | str) | Literal[2] # Error
|
||||
36 36 |
|
||||
37 37 | # Should emit for union in generic parent type.
|
||||
|
||||
PYI030.pyi:35:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
33 | # Should handle user parentheses when fixing.
|
||||
34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
|
@ -111,7 +211,17 @@ PYI030.pyi:35:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:38:15: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
32 32 |
|
||||
33 33 | # Should handle user parentheses when fixing.
|
||||
34 34 | field9: Literal[1] | (Literal[2] | str) # Error
|
||||
35 |-field10: (Literal[1] | str) | Literal[2] # Error
|
||||
35 |+field10: Literal[1, 2] | str # Error
|
||||
36 36 |
|
||||
37 37 | # Should emit for union in generic parent type.
|
||||
38 38 | field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
|
||||
PYI030.pyi:38:15: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
37 | # Should emit for union in generic parent type.
|
||||
38 | field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
|
@ -121,7 +231,17 @@ PYI030.pyi:38:15: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:41:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
ℹ Safe fix
|
||||
35 35 | field10: (Literal[1] | str) | Literal[2] # Error
|
||||
36 36 |
|
||||
37 37 | # Should emit for union in generic parent type.
|
||||
38 |-field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
38 |+field11: dict[Literal[1, 2], str] # Error
|
||||
39 39 |
|
||||
40 40 | # Should emit for unions with more than two cases
|
||||
41 41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
|
||||
PYI030.pyi:41:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
|
|
||||
40 | # Should emit for unions with more than two cases
|
||||
41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
|
@ -130,7 +250,17 @@ PYI030.pyi:41:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:42:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
38 38 | field11: dict[Literal[1] | Literal[2], str] # Error
|
||||
39 39 |
|
||||
40 40 | # Should emit for unions with more than two cases
|
||||
41 |-field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
41 |+field12: Literal[1, 2, 3] # Error
|
||||
42 42 | field13: Literal[1] | Literal[2] | Literal[3] | Literal[4] # Error
|
||||
43 43 |
|
||||
44 44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
|
||||
PYI030.pyi:42:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
40 | # Should emit for unions with more than two cases
|
||||
41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
|
@ -141,7 +271,17 @@ PYI030.pyi:42:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:45:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
ℹ Safe fix
|
||||
39 39 |
|
||||
40 40 | # Should emit for unions with more than two cases
|
||||
41 41 | field12: Literal[1] | Literal[2] | Literal[3] # Error
|
||||
42 |-field13: Literal[1] | Literal[2] | Literal[3] | Literal[4] # Error
|
||||
42 |+field13: Literal[1, 2, 3, 4] # Error
|
||||
43 43 |
|
||||
44 44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
45 45 | field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
|
||||
PYI030.pyi:45:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3]`
|
||||
|
|
||||
44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
45 | field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
|
@ -151,7 +291,17 @@ PYI030.pyi:45:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:48:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, "foo", True]`
|
||||
ℹ Safe fix
|
||||
42 42 | field13: Literal[1] | Literal[2] | Literal[3] | Literal[4] # Error
|
||||
43 43 |
|
||||
44 44 | # Should emit for unions with more than two cases, even if not directly adjacent
|
||||
45 |-field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
45 |+field14: Literal[1, 2, 3] | str # Error
|
||||
46 46 |
|
||||
47 47 | # Should emit for unions with mixed literal internal types
|
||||
48 48 | field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
|
||||
PYI030.pyi:48:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, "foo", True]`
|
||||
|
|
||||
47 | # Should emit for unions with mixed literal internal types
|
||||
48 | field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
|
@ -161,7 +311,17 @@ PYI030.pyi:48:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:51:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 1]`
|
||||
ℹ Safe fix
|
||||
45 45 | field14: Literal[1] | Literal[2] | str | Literal[3] # Error
|
||||
46 46 |
|
||||
47 47 | # Should emit for unions with mixed literal internal types
|
||||
48 |-field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
48 |+field15: Literal[1, "foo", True] # Error
|
||||
49 49 |
|
||||
50 50 | # Shouldn't emit for duplicate field types with same value; covered by Y016
|
||||
51 51 | field16: Literal[1] | Literal[1] # OK
|
||||
|
||||
PYI030.pyi:51:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 1]`
|
||||
|
|
||||
50 | # Shouldn't emit for duplicate field types with same value; covered by Y016
|
||||
51 | field16: Literal[1] | Literal[1] # OK
|
||||
|
@ -171,7 +331,17 @@ PYI030.pyi:51:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:60:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
48 48 | field15: Literal[1] | Literal["foo"] | Literal[True] # Error
|
||||
49 49 |
|
||||
50 50 | # Shouldn't emit for duplicate field types with same value; covered by Y016
|
||||
51 |-field16: Literal[1] | Literal[1] # OK
|
||||
51 |+field16: Literal[1, 1] # OK
|
||||
52 52 |
|
||||
53 53 | # Shouldn't emit if in new parent type
|
||||
54 54 | field17: Literal[1] | dict[Literal[2], str] # OK
|
||||
|
||||
PYI030.pyi:60:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
59 | # Should respect name of literal type used
|
||||
60 | field19: typing.Literal[1] | typing.Literal[2] # Error
|
||||
|
@ -181,7 +351,17 @@ PYI030.pyi:60:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:63:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
57 57 | field18: dict[Literal[1], Literal[2]] # OK
|
||||
58 58 |
|
||||
59 59 | # Should respect name of literal type used
|
||||
60 |-field19: typing.Literal[1] | typing.Literal[2] # Error
|
||||
60 |+field19: typing.Literal[1, 2] # Error
|
||||
61 61 |
|
||||
62 62 | # Should emit in cases with newlines
|
||||
63 63 | field20: typing.Union[
|
||||
|
||||
PYI030.pyi:63:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
62 | # Should emit in cases with newlines
|
||||
63 | field20: typing.Union[
|
||||
|
@ -197,7 +377,22 @@ PYI030.pyi:63:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:71:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
60 60 | field19: typing.Literal[1] | typing.Literal[2] # Error
|
||||
61 61 |
|
||||
62 62 | # Should emit in cases with newlines
|
||||
63 |-field20: typing.Union[
|
||||
64 |- Literal[
|
||||
65 |- 1 # test
|
||||
66 |- ],
|
||||
67 |- Literal[2],
|
||||
68 |-] # Error, newline and comment will not be emitted in message
|
||||
63 |+field20: Literal[1, 2] # Error, newline and comment will not be emitted in message
|
||||
69 64 |
|
||||
70 65 | # Should handle multiple unions with multiple members
|
||||
71 66 | field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
|
||||
PYI030.pyi:71:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
70 | # Should handle multiple unions with multiple members
|
||||
71 | field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
|
@ -207,7 +402,17 @@ PYI030.pyi:71:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:74:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
68 68 | ] # Error, newline and comment will not be emitted in message
|
||||
69 69 |
|
||||
70 70 | # Should handle multiple unions with multiple members
|
||||
71 |-field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
71 |+field21: Literal[1, 2, 3, 4] # Error
|
||||
72 72 |
|
||||
73 73 | # Should emit in cases with `typing.Union` instead of `|`
|
||||
74 74 | field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
|
||||
PYI030.pyi:74:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
73 | # Should emit in cases with `typing.Union` instead of `|`
|
||||
74 | field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
|
@ -217,7 +422,17 @@ PYI030.pyi:74:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:77:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
71 71 | field21: Literal[1, 2] | Literal[3, 4] # Error
|
||||
72 72 |
|
||||
73 73 | # Should emit in cases with `typing.Union` instead of `|`
|
||||
74 |-field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
74 |+field22: Literal[1, 2] # Error
|
||||
75 75 |
|
||||
76 76 | # Should emit in cases with `typing_extensions.Literal`
|
||||
77 77 | field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
|
||||
PYI030.pyi:77:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
76 | # Should emit in cases with `typing_extensions.Literal`
|
||||
77 | field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
|
@ -227,7 +442,17 @@ PYI030.pyi:77:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:80:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
74 74 | field22: typing.Union[Literal[1], Literal[2]] # Error
|
||||
75 75 |
|
||||
76 76 | # Should emit in cases with `typing_extensions.Literal`
|
||||
77 |-field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
77 |+field23: typing_extensions.Literal[1, 2] # Error
|
||||
78 78 |
|
||||
79 79 | # Should emit in cases with nested `typing.Union`
|
||||
80 80 | field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
|
||||
PYI030.pyi:80:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
79 | # Should emit in cases with nested `typing.Union`
|
||||
80 | field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
|
@ -237,7 +462,17 @@ PYI030.pyi:80:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:83:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
ℹ Safe fix
|
||||
77 77 | field23: typing_extensions.Literal[1] | typing_extensions.Literal[2] # Error
|
||||
78 78 |
|
||||
79 79 | # Should emit in cases with nested `typing.Union`
|
||||
80 |-field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
80 |+field24: typing.Union[Literal[1, 2], str] # Error
|
||||
81 81 |
|
||||
82 82 | # Should emit in cases with mixed `typing.Union` and `|`
|
||||
83 83 | field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
|
||||
PYI030.pyi:83:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2]`
|
||||
|
|
||||
82 | # Should emit in cases with mixed `typing.Union` and `|`
|
||||
83 | field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
|
@ -247,7 +482,17 @@ PYI030.pyi:83:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:86:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
80 80 | field24: typing.Union[Literal[1], typing.Union[Literal[2], str]] # Error
|
||||
81 81 |
|
||||
82 82 | # Should emit in cases with mixed `typing.Union` and `|`
|
||||
83 |-field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
83 |+field25: typing.Union[Literal[1, 2], str] # Error
|
||||
84 84 |
|
||||
85 85 | # Should emit only once in cases with multiple nested `typing.Union`
|
||||
86 86 | field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
|
||||
PYI030.pyi:86:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
85 | # Should emit only once in cases with multiple nested `typing.Union`
|
||||
86 | field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
|
@ -257,7 +502,17 @@ PYI030.pyi:86:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
PYI030.pyi:89:10: PYI030 Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
ℹ Safe fix
|
||||
83 83 | field25: typing.Union[Literal[1], Literal[2] | str] # Error
|
||||
84 84 |
|
||||
85 85 | # Should emit only once in cases with multiple nested `typing.Union`
|
||||
86 |-field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
86 |+field24: Literal[1, 2, 3, 4] # Error
|
||||
87 87 |
|
||||
88 88 | # Should use the first literal subscript attribute when fixing
|
||||
89 89 | field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||
|
||||
PYI030.pyi:89:10: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal[1, 2, 3, 4]`
|
||||
|
|
||||
88 | # Should use the first literal subscript attribute when fixing
|
||||
89 | field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||
|
@ -265,4 +520,11 @@ PYI030.pyi:89:10: PYI030 Multiple literal members in a union. Use a single liter
|
|||
|
|
||||
= help: Replace with a single `Literal`
|
||||
|
||||
ℹ Safe fix
|
||||
86 86 | field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]]] # Error
|
||||
87 87 |
|
||||
88 88 | # Should use the first literal subscript attribute when fixing
|
||||
89 |-field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||
89 |+field25: typing.Union[typing_extensions.Literal[1, 2, 3, 4], str] # Error
|
||||
|
||||
|
||||
|
|
|
@ -56,11 +56,8 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::InDictKeys, Path::new("SIM118.py"))]
|
||||
#[test_case(Rule::YodaConditions, Path::new("SIM300.py"))]
|
||||
#[test_case(Rule::IfElseBlockInsteadOfDictGet, Path::new("SIM401.py"))]
|
||||
#[test_case(Rule::DictGetWithNoneDefault, Path::new("SIM910.py"))]
|
||||
#[test_case(Rule::IfWithSameArms, Path::new("SIM114.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
"preview__{}_{}",
|
||||
|
|
|
@ -266,10 +266,6 @@ pub(crate) fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) {
|
|||
match value.as_ref() {
|
||||
Expr::Dict(_) | Expr::DictComp(_) => {}
|
||||
Expr::Name(name) => {
|
||||
if checker.settings.preview.is_disabled() {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(binding) = checker
|
||||
.semantic()
|
||||
.only_binding(name)
|
||||
|
|
|
@ -94,7 +94,6 @@ pub(crate) fn if_with_same_arms(checker: &mut Checker, stmt_if: &ast::StmtIf) {
|
|||
TextRange::new(current_branch.start(), following_branch.end()),
|
||||
);
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
diagnostic.try_set_fix(|| {
|
||||
merge_branches(
|
||||
stmt_if,
|
||||
|
@ -104,7 +103,6 @@ pub(crate) fn if_with_same_arms(checker: &mut Checker, stmt_if: &ast::StmtIf) {
|
|||
checker.indexer(),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ fn key_in_dict(
|
|||
{
|
||||
// The fix is only safe if we know the expression is a dictionary, since other types
|
||||
// can define a `.keys()` method.
|
||||
let applicability = if checker.settings.preview.is_enabled() {
|
||||
let applicability = {
|
||||
let is_dict = value.as_name_expr().is_some_and(|name| {
|
||||
let Some(binding) = checker
|
||||
.semantic()
|
||||
|
@ -143,8 +143,6 @@ fn key_in_dict(
|
|||
} else {
|
||||
Applicability::Unsafe
|
||||
}
|
||||
} else {
|
||||
Applicability::Unsafe
|
||||
};
|
||||
|
||||
// If the `.keys()` is followed by (e.g.) a keyword, we need to insert a space,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
|
||||
---
|
||||
SIM114.py:2:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
SIM114.py:2:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
1 | # Errors
|
||||
2 | / if a:
|
||||
|
@ -14,7 +14,17 @@ SIM114.py:2:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:7:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
1 1 | # Errors
|
||||
2 |-if a:
|
||||
3 |- b
|
||||
4 |-elif c:
|
||||
2 |+if a or c:
|
||||
5 3 | b
|
||||
6 4 |
|
||||
7 5 | if a: # we preserve comments, too!
|
||||
|
||||
SIM114.py:7:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
5 | b
|
||||
6 |
|
||||
|
@ -28,7 +38,19 @@ SIM114.py:7:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:12:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
4 4 | elif c:
|
||||
5 5 | b
|
||||
6 6 |
|
||||
7 |-if a: # we preserve comments, too!
|
||||
8 |- b
|
||||
9 |-elif c: # but not on the second branch
|
||||
7 |+if a or c: # we preserve comments, too!
|
||||
10 8 | b
|
||||
11 9 |
|
||||
12 10 | if x == 1:
|
||||
|
||||
SIM114.py:12:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
10 | b
|
||||
11 |
|
||||
|
@ -44,7 +66,20 @@ SIM114.py:12:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:19:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
9 9 | elif c: # but not on the second branch
|
||||
10 10 | b
|
||||
11 11 |
|
||||
12 |-if x == 1:
|
||||
13 |- for _ in range(20):
|
||||
14 |- print("hello")
|
||||
15 |-elif x == 2:
|
||||
12 |+if x == 1 or x == 2:
|
||||
16 13 | for _ in range(20):
|
||||
17 14 | print("hello")
|
||||
18 15 |
|
||||
|
||||
SIM114.py:19:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
17 | print("hello")
|
||||
18 |
|
||||
|
@ -62,7 +97,21 @@ SIM114.py:19:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:28:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
16 16 | for _ in range(20):
|
||||
17 17 | print("hello")
|
||||
18 18 |
|
||||
19 |-if x == 1:
|
||||
20 |- if True:
|
||||
21 |- for _ in range(20):
|
||||
22 |- print("hello")
|
||||
23 |-elif x == 2:
|
||||
19 |+if x == 1 or x == 2:
|
||||
24 20 | if True:
|
||||
25 21 | for _ in range(20):
|
||||
26 22 | print("hello")
|
||||
|
||||
SIM114.py:28:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
26 | print("hello")
|
||||
27 |
|
||||
|
@ -86,7 +135,24 @@ SIM114.py:28:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:29:5: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
25 25 | for _ in range(20):
|
||||
26 26 | print("hello")
|
||||
27 27 |
|
||||
28 |-if x == 1:
|
||||
29 |- if True:
|
||||
30 |- for _ in range(20):
|
||||
31 |- print("hello")
|
||||
32 |- elif False:
|
||||
33 |- for _ in range(20):
|
||||
34 |- print("hello")
|
||||
35 |-elif x == 2:
|
||||
28 |+if x == 1 or x == 2:
|
||||
36 29 | if True:
|
||||
37 30 | for _ in range(20):
|
||||
38 31 | print("hello")
|
||||
|
||||
SIM114.py:29:5: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
28 | if x == 1:
|
||||
29 | if True:
|
||||
|
@ -102,7 +168,20 @@ SIM114.py:29:5: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:36:5: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
26 26 | print("hello")
|
||||
27 27 |
|
||||
28 28 | if x == 1:
|
||||
29 |- if True:
|
||||
30 |- for _ in range(20):
|
||||
31 |- print("hello")
|
||||
32 |- elif False:
|
||||
29 |+ if True or False:
|
||||
33 30 | for _ in range(20):
|
||||
34 31 | print("hello")
|
||||
35 32 | elif x == 2:
|
||||
|
||||
SIM114.py:36:5: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
34 | print("hello")
|
||||
35 | elif x == 2:
|
||||
|
@ -119,7 +198,20 @@ SIM114.py:36:5: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:43:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
33 33 | for _ in range(20):
|
||||
34 34 | print("hello")
|
||||
35 35 | elif x == 2:
|
||||
36 |- if True:
|
||||
37 |- for _ in range(20):
|
||||
38 |- print("hello")
|
||||
39 |- elif False:
|
||||
36 |+ if True or False:
|
||||
40 37 | for _ in range(20):
|
||||
41 38 | print("hello")
|
||||
42 39 |
|
||||
|
||||
SIM114.py:43:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
41 | print("hello")
|
||||
42 |
|
||||
|
@ -148,7 +240,19 @@ SIM114.py:43:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:67:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
55 55 | and i == 12
|
||||
56 56 | and j == 13
|
||||
57 57 | and k == 14
|
||||
58 |-):
|
||||
59 |- pass
|
||||
60 |-elif 1 == 2:
|
||||
58 |+) or 1 == 2:
|
||||
61 59 | pass
|
||||
62 60 |
|
||||
63 61 | if result.eofs == "O":
|
||||
|
||||
SIM114.py:67:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
65 | elif result.eofs == "S":
|
||||
66 | skipped = 1
|
||||
|
@ -162,7 +266,19 @@ SIM114.py:67:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:69:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
64 64 | pass
|
||||
65 65 | elif result.eofs == "S":
|
||||
66 66 | skipped = 1
|
||||
67 |-elif result.eofs == "F":
|
||||
68 |- errors = 1
|
||||
69 |-elif result.eofs == "E":
|
||||
67 |+elif result.eofs == "F" or result.eofs == "E":
|
||||
70 68 | errors = 1
|
||||
71 69 | elif result.eofs == "X":
|
||||
72 70 | errors = 1
|
||||
|
||||
SIM114.py:69:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
67 | elif result.eofs == "F":
|
||||
68 | errors = 1
|
||||
|
@ -176,7 +292,19 @@ SIM114.py:69:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:71:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
66 66 | skipped = 1
|
||||
67 67 | elif result.eofs == "F":
|
||||
68 68 | errors = 1
|
||||
69 |-elif result.eofs == "E":
|
||||
70 |- errors = 1
|
||||
71 |-elif result.eofs == "X":
|
||||
69 |+elif result.eofs == "E" or result.eofs == "X":
|
||||
72 70 | errors = 1
|
||||
73 71 | elif result.eofs == "C":
|
||||
74 72 | errors = 1
|
||||
|
||||
SIM114.py:71:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
69 | elif result.eofs == "E":
|
||||
70 | errors = 1
|
||||
|
@ -188,7 +316,19 @@ SIM114.py:71:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:118:5: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
68 68 | errors = 1
|
||||
69 69 | elif result.eofs == "E":
|
||||
70 70 | errors = 1
|
||||
71 |-elif result.eofs == "X":
|
||||
72 |- errors = 1
|
||||
73 |-elif result.eofs == "C":
|
||||
71 |+elif result.eofs == "X" or result.eofs == "C":
|
||||
74 72 | errors = 1
|
||||
75 73 |
|
||||
76 74 |
|
||||
|
||||
SIM114.py:118:5: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
116 | a = True
|
||||
117 | b = False
|
||||
|
@ -203,7 +343,19 @@ SIM114.py:118:5: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:122:5: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
115 115 | def func():
|
||||
116 116 | a = True
|
||||
117 117 | b = False
|
||||
118 |- if a > b: # end-of-line
|
||||
119 |- return 3
|
||||
120 |- elif a == b:
|
||||
118 |+ if a > b or a == b: # end-of-line
|
||||
121 119 | return 3
|
||||
122 120 | elif a < b: # end-of-line
|
||||
123 121 | return 4
|
||||
|
||||
SIM114.py:122:5: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
120 | elif a == b:
|
||||
121 | return 3
|
||||
|
@ -216,7 +368,19 @@ SIM114.py:122:5: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:132:5: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
119 119 | return 3
|
||||
120 120 | elif a == b:
|
||||
121 121 | return 3
|
||||
122 |- elif a < b: # end-of-line
|
||||
123 |- return 4
|
||||
124 |- elif b is None:
|
||||
122 |+ elif a < b or b is None: # end-of-line
|
||||
125 123 | return 4
|
||||
126 124 |
|
||||
127 125 |
|
||||
|
||||
SIM114.py:132:5: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
130 | a = True
|
||||
131 | b = False
|
||||
|
@ -229,7 +393,19 @@ SIM114.py:132:5: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:138:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
129 129 | """Ensure that the named expression is parenthesized when merged."""
|
||||
130 130 | a = True
|
||||
131 131 | b = False
|
||||
132 |- if a > b: # end-of-line
|
||||
133 |- return 3
|
||||
134 |- elif a := 1:
|
||||
132 |+ if a > b or (a := 1): # end-of-line
|
||||
135 133 | return 3
|
||||
136 134 |
|
||||
137 135 |
|
||||
|
||||
SIM114.py:138:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
138 | / if a: # we preserve comments, too!
|
||||
139 | | b
|
||||
|
@ -239,7 +415,19 @@ SIM114.py:138:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:144:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
135 135 | return 3
|
||||
136 136 |
|
||||
137 137 |
|
||||
138 |-if a: # we preserve comments, too!
|
||||
139 |- b
|
||||
140 |-elif c: # but not on the second branch
|
||||
138 |+if a or c: # we preserve comments, too!
|
||||
141 139 | b
|
||||
142 140 |
|
||||
143 141 |
|
||||
|
||||
SIM114.py:144:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
144 | / if a: b # here's a comment
|
||||
145 | | elif c: b
|
||||
|
@ -247,7 +435,18 @@ SIM114.py:144:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
SIM114.py:148:1: SIM114 Combine `if` branches using logical `or` operator
|
||||
ℹ Safe fix
|
||||
141 141 | b
|
||||
142 142 |
|
||||
143 143 |
|
||||
144 |-if a: b # here's a comment
|
||||
145 |-elif c: b
|
||||
144 |+if a or c: b # here's a comment
|
||||
146 145 |
|
||||
147 146 |
|
||||
148 147 | if(x > 200): pass
|
||||
|
||||
SIM114.py:148:1: SIM114 [*] Combine `if` branches using logical `or` operator
|
||||
|
|
||||
148 | / if(x > 200): pass
|
||||
149 | | elif(100 < x and x < 200 and 300 < y and y < 800):
|
||||
|
@ -256,4 +455,13 @@ SIM114.py:148:1: SIM114 Combine `if` branches using logical `or` operator
|
|||
|
|
||||
= help: Combine `if` branches
|
||||
|
||||
ℹ Safe fix
|
||||
145 145 | elif c: b
|
||||
146 146 |
|
||||
147 147 |
|
||||
148 |-if(x > 200): pass
|
||||
149 |-elif(100 < x and x < 200 and 300 < y and y < 800):
|
||||
150 |- pass
|
||||
148 |+if(x > 200) or (100 < x and x < 200 and 300 < y and y < 800): pass
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ SIM118.py:3:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
1 1 | obj = {}
|
||||
2 2 |
|
||||
3 |-key in obj.keys() # SIM118
|
||||
|
@ -32,7 +32,7 @@ SIM118.py:5:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
2 2 |
|
||||
3 3 | key in obj.keys() # SIM118
|
||||
4 4 |
|
||||
|
@ -53,7 +53,7 @@ SIM118.py:7:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
4 4 |
|
||||
5 5 | key not in obj.keys() # SIM118
|
||||
6 6 |
|
||||
|
@ -74,7 +74,7 @@ SIM118.py:9:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
6 6 |
|
||||
7 7 | foo["bar"] in obj.keys() # SIM118
|
||||
8 8 |
|
||||
|
@ -95,7 +95,7 @@ SIM118.py:11:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
8 8 |
|
||||
9 9 | foo["bar"] not in obj.keys() # SIM118
|
||||
10 10 |
|
||||
|
@ -116,7 +116,7 @@ SIM118.py:13:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.key
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
10 10 |
|
||||
11 11 | foo['bar'] in obj.keys() # SIM118
|
||||
12 12 |
|
||||
|
@ -137,7 +137,7 @@ SIM118.py:15:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
12 12 |
|
||||
13 13 | foo['bar'] not in obj.keys() # SIM118
|
||||
14 14 |
|
||||
|
@ -158,7 +158,7 @@ SIM118.py:17:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.key
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
14 14 |
|
||||
15 15 | foo() in obj.keys() # SIM118
|
||||
16 16 |
|
||||
|
@ -178,7 +178,7 @@ SIM118.py:19:5: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
16 16 |
|
||||
17 17 | foo() not in obj.keys() # SIM118
|
||||
18 18 |
|
||||
|
@ -199,7 +199,7 @@ SIM118.py:26:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
23 23 | if some_property(key):
|
||||
24 24 | del obj[key]
|
||||
25 25 |
|
||||
|
@ -220,7 +220,7 @@ SIM118.py:28:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
25 25 |
|
||||
26 26 | [k for k in obj.keys()] # SIM118
|
||||
27 27 |
|
||||
|
@ -241,7 +241,7 @@ SIM118.py:30:11: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
27 27 |
|
||||
28 28 | {k for k in obj.keys()} # SIM118
|
||||
29 29 |
|
||||
|
@ -262,7 +262,7 @@ SIM118.py:32:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
29 29 |
|
||||
30 30 | {k: k for k in obj.keys()} # SIM118
|
||||
31 31 |
|
||||
|
@ -324,7 +324,7 @@ SIM118.py:50:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
47 47 |
|
||||
48 48 |
|
||||
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
|
@ -344,7 +344,7 @@ SIM118.py:51:2: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
48 48 |
|
||||
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
50 50 | key in obj.keys()and foo
|
||||
|
@ -365,7 +365,7 @@ SIM118.py:52:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
|||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
50 50 | key in obj.keys()and foo
|
||||
51 51 | (key in obj.keys())and foo
|
||||
|
|
|
@ -98,4 +98,25 @@ SIM910.py:27:1: SIM910 [*] Use `({}).get(key)` instead of `({}).get(key, None)`
|
|||
29 29 | # SIM910
|
||||
30 30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11}
|
||||
|
||||
SIM910.py:31:7: SIM910 [*] Use `ages.get("Cat")` instead of `ages.get("Cat", None)`
|
||||
|
|
||||
29 | # SIM910
|
||||
30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11}
|
||||
31 | age = ages.get("Cat", None)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ SIM910
|
||||
32 |
|
||||
33 | # OK
|
||||
|
|
||||
= help: Replace `ages.get("Cat", None)` with `ages.get("Cat")`
|
||||
|
||||
ℹ Safe fix
|
||||
28 28 |
|
||||
29 29 | # SIM910
|
||||
30 30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11}
|
||||
31 |-age = ages.get("Cat", None)
|
||||
31 |+age = ages.get("Cat")
|
||||
32 32 |
|
||||
33 33 | # OK
|
||||
34 34 | ages = ["Tom", "Maria", "Dog"]
|
||||
|
||||
|
||||
|
|
|
@ -1,401 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
|
||||
---
|
||||
SIM118.py:3:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
1 | obj = {}
|
||||
2 |
|
||||
3 | key in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^ SIM118
|
||||
4 |
|
||||
5 | key not in obj.keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | obj = {}
|
||||
2 2 |
|
||||
3 |-key in obj.keys() # SIM118
|
||||
3 |+key in obj # SIM118
|
||||
4 4 |
|
||||
5 5 | key not in obj.keys() # SIM118
|
||||
6 6 |
|
||||
|
||||
SIM118.py:5:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
|
||||
|
|
||||
3 | key in obj.keys() # SIM118
|
||||
4 |
|
||||
5 | key not in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
6 |
|
||||
7 | foo["bar"] in obj.keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 |
|
||||
3 3 | key in obj.keys() # SIM118
|
||||
4 4 |
|
||||
5 |-key not in obj.keys() # SIM118
|
||||
5 |+key not in obj # SIM118
|
||||
6 6 |
|
||||
7 7 | foo["bar"] in obj.keys() # SIM118
|
||||
8 8 |
|
||||
|
||||
SIM118.py:7:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
5 | key not in obj.keys() # SIM118
|
||||
6 |
|
||||
7 | foo["bar"] in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
8 |
|
||||
9 | foo["bar"] not in obj.keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
4 4 |
|
||||
5 5 | key not in obj.keys() # SIM118
|
||||
6 6 |
|
||||
7 |-foo["bar"] in obj.keys() # SIM118
|
||||
7 |+foo["bar"] in obj # SIM118
|
||||
8 8 |
|
||||
9 9 | foo["bar"] not in obj.keys() # SIM118
|
||||
10 10 |
|
||||
|
||||
SIM118.py:9:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
|
||||
|
|
||||
7 | foo["bar"] in obj.keys() # SIM118
|
||||
8 |
|
||||
9 | foo["bar"] not in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
10 |
|
||||
11 | foo['bar'] in obj.keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
6 6 |
|
||||
7 7 | foo["bar"] in obj.keys() # SIM118
|
||||
8 8 |
|
||||
9 |-foo["bar"] not in obj.keys() # SIM118
|
||||
9 |+foo["bar"] not in obj # SIM118
|
||||
10 10 |
|
||||
11 11 | foo['bar'] in obj.keys() # SIM118
|
||||
12 12 |
|
||||
|
||||
SIM118.py:11:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
9 | foo["bar"] not in obj.keys() # SIM118
|
||||
10 |
|
||||
11 | foo['bar'] in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
12 |
|
||||
13 | foo['bar'] not in obj.keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
8 8 |
|
||||
9 9 | foo["bar"] not in obj.keys() # SIM118
|
||||
10 10 |
|
||||
11 |-foo['bar'] in obj.keys() # SIM118
|
||||
11 |+foo['bar'] in obj # SIM118
|
||||
12 12 |
|
||||
13 13 | foo['bar'] not in obj.keys() # SIM118
|
||||
14 14 |
|
||||
|
||||
SIM118.py:13:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
|
||||
|
|
||||
11 | foo['bar'] in obj.keys() # SIM118
|
||||
12 |
|
||||
13 | foo['bar'] not in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
14 |
|
||||
15 | foo() in obj.keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
10 10 |
|
||||
11 11 | foo['bar'] in obj.keys() # SIM118
|
||||
12 12 |
|
||||
13 |-foo['bar'] not in obj.keys() # SIM118
|
||||
13 |+foo['bar'] not in obj # SIM118
|
||||
14 14 |
|
||||
15 15 | foo() in obj.keys() # SIM118
|
||||
16 16 |
|
||||
|
||||
SIM118.py:15:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
13 | foo['bar'] not in obj.keys() # SIM118
|
||||
14 |
|
||||
15 | foo() in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
16 |
|
||||
17 | foo() not in obj.keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
12 12 |
|
||||
13 13 | foo['bar'] not in obj.keys() # SIM118
|
||||
14 14 |
|
||||
15 |-foo() in obj.keys() # SIM118
|
||||
15 |+foo() in obj # SIM118
|
||||
16 16 |
|
||||
17 17 | foo() not in obj.keys() # SIM118
|
||||
18 18 |
|
||||
|
||||
SIM118.py:17:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
|
||||
|
|
||||
15 | foo() in obj.keys() # SIM118
|
||||
16 |
|
||||
17 | foo() not in obj.keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
18 |
|
||||
19 | for key in obj.keys(): # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
14 14 |
|
||||
15 15 | foo() in obj.keys() # SIM118
|
||||
16 16 |
|
||||
17 |-foo() not in obj.keys() # SIM118
|
||||
17 |+foo() not in obj # SIM118
|
||||
18 18 |
|
||||
19 19 | for key in obj.keys(): # SIM118
|
||||
20 20 | pass
|
||||
|
||||
SIM118.py:19:5: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
17 | foo() not in obj.keys() # SIM118
|
||||
18 |
|
||||
19 | for key in obj.keys(): # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^ SIM118
|
||||
20 | pass
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
16 16 |
|
||||
17 17 | foo() not in obj.keys() # SIM118
|
||||
18 18 |
|
||||
19 |-for key in obj.keys(): # SIM118
|
||||
19 |+for key in obj: # SIM118
|
||||
20 20 | pass
|
||||
21 21 |
|
||||
22 22 | for key in list(obj.keys()):
|
||||
|
||||
SIM118.py:26:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
24 | del obj[key]
|
||||
25 |
|
||||
26 | [k for k in obj.keys()] # SIM118
|
||||
| ^^^^^^^^^^^^^^^ SIM118
|
||||
27 |
|
||||
28 | {k for k in obj.keys()} # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
23 23 | if some_property(key):
|
||||
24 24 | del obj[key]
|
||||
25 25 |
|
||||
26 |-[k for k in obj.keys()] # SIM118
|
||||
26 |+[k for k in obj] # SIM118
|
||||
27 27 |
|
||||
28 28 | {k for k in obj.keys()} # SIM118
|
||||
29 29 |
|
||||
|
||||
SIM118.py:28:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
26 | [k for k in obj.keys()] # SIM118
|
||||
27 |
|
||||
28 | {k for k in obj.keys()} # SIM118
|
||||
| ^^^^^^^^^^^^^^^ SIM118
|
||||
29 |
|
||||
30 | {k: k for k in obj.keys()} # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
25 25 |
|
||||
26 26 | [k for k in obj.keys()] # SIM118
|
||||
27 27 |
|
||||
28 |-{k for k in obj.keys()} # SIM118
|
||||
28 |+{k for k in obj} # SIM118
|
||||
29 29 |
|
||||
30 30 | {k: k for k in obj.keys()} # SIM118
|
||||
31 31 |
|
||||
|
||||
SIM118.py:30:11: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
28 | {k for k in obj.keys()} # SIM118
|
||||
29 |
|
||||
30 | {k: k for k in obj.keys()} # SIM118
|
||||
| ^^^^^^^^^^^^^^^ SIM118
|
||||
31 |
|
||||
32 | (k for k in obj.keys()) # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
27 27 |
|
||||
28 28 | {k for k in obj.keys()} # SIM118
|
||||
29 29 |
|
||||
30 |-{k: k for k in obj.keys()} # SIM118
|
||||
30 |+{k: k for k in obj} # SIM118
|
||||
31 31 |
|
||||
32 32 | (k for k in obj.keys()) # SIM118
|
||||
33 33 |
|
||||
|
||||
SIM118.py:32:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
30 | {k: k for k in obj.keys()} # SIM118
|
||||
31 |
|
||||
32 | (k for k in obj.keys()) # SIM118
|
||||
| ^^^^^^^^^^^^^^^ SIM118
|
||||
33 |
|
||||
34 | key in (obj or {}).keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
29 29 |
|
||||
30 30 | {k: k for k in obj.keys()} # SIM118
|
||||
31 31 |
|
||||
32 |-(k for k in obj.keys()) # SIM118
|
||||
32 |+(k for k in obj) # SIM118
|
||||
33 33 |
|
||||
34 34 | key in (obj or {}).keys() # SIM118
|
||||
35 35 |
|
||||
|
||||
SIM118.py:34:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
32 | (k for k in obj.keys()) # SIM118
|
||||
33 |
|
||||
34 | key in (obj or {}).keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
35 |
|
||||
36 | (key) in (obj or {}).keys() # SIM118
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
31 31 |
|
||||
32 32 | (k for k in obj.keys()) # SIM118
|
||||
33 33 |
|
||||
34 |-key in (obj or {}).keys() # SIM118
|
||||
34 |+key in (obj or {}) # SIM118
|
||||
35 35 |
|
||||
36 36 | (key) in (obj or {}).keys() # SIM118
|
||||
37 37 |
|
||||
|
||||
SIM118.py:36:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
34 | key in (obj or {}).keys() # SIM118
|
||||
35 |
|
||||
36 | (key) in (obj or {}).keys() # SIM118
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
37 |
|
||||
38 | from typing import KeysView
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
33 33 |
|
||||
34 34 | key in (obj or {}).keys() # SIM118
|
||||
35 35 |
|
||||
36 |-(key) in (obj or {}).keys() # SIM118
|
||||
36 |+(key) in (obj or {}) # SIM118
|
||||
37 37 |
|
||||
38 38 | from typing import KeysView
|
||||
39 39 |
|
||||
|
||||
SIM118.py:50:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
50 | key in obj.keys()and foo
|
||||
| ^^^^^^^^^^^^^^^^^ SIM118
|
||||
51 | (key in obj.keys())and foo
|
||||
52 | key in (obj.keys())and foo
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
47 47 |
|
||||
48 48 |
|
||||
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
50 |-key in obj.keys()and foo
|
||||
50 |+key in obj and foo
|
||||
51 51 | (key in obj.keys())and foo
|
||||
52 52 | key in (obj.keys())and foo
|
||||
53 53 |
|
||||
|
||||
SIM118.py:51:2: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
50 | key in obj.keys()and foo
|
||||
51 | (key in obj.keys())and foo
|
||||
| ^^^^^^^^^^^^^^^^^ SIM118
|
||||
52 | key in (obj.keys())and foo
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
48 48 |
|
||||
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
50 50 | key in obj.keys()and foo
|
||||
51 |-(key in obj.keys())and foo
|
||||
51 |+(key in obj)and foo
|
||||
52 52 | key in (obj.keys())and foo
|
||||
53 53 |
|
||||
54 54 | # Regression test for: https://github.com/astral-sh/ruff/issues/7200
|
||||
|
||||
SIM118.py:52:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
50 | key in obj.keys()and foo
|
||||
51 | (key in obj.keys())and foo
|
||||
52 | key in (obj.keys())and foo
|
||||
| ^^^^^^^^^^^^^^^^^^^ SIM118
|
||||
53 |
|
||||
54 | # Regression test for: https://github.com/astral-sh/ruff/issues/7200
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Safe fix
|
||||
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
|
||||
50 50 | key in obj.keys()and foo
|
||||
51 51 | (key in obj.keys())and foo
|
||||
52 |-key in (obj.keys())and foo
|
||||
52 |+key in (obj)and foo
|
||||
53 53 |
|
||||
54 54 | # Regression test for: https://github.com/astral-sh/ruff/issues/7200
|
||||
55 55 | for key in (
|
||||
|
||||
SIM118.py:55:5: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
|
||||
|
|
||||
54 | # Regression test for: https://github.com/astral-sh/ruff/issues/7200
|
||||
55 | for key in (
|
||||
| _____^
|
||||
56 | | self.experiment.surveys[0]
|
||||
57 | | .stations[0]
|
||||
58 | | .keys()
|
||||
59 | | ):
|
||||
| |_^ SIM118
|
||||
60 | continue
|
||||
|
|
||||
= help: Remove `.keys()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
55 55 | for key in (
|
||||
56 56 | self.experiment.surveys[0]
|
||||
57 57 | .stations[0]
|
||||
58 |- .keys()
|
||||
58 |+
|
||||
59 59 | ):
|
||||
60 60 | continue
|
||||
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
|
||||
---
|
||||
SIM910.py:2:1: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)`
|
||||
|
|
||||
1 | # SIM910
|
||||
2 | {}.get(key, None)
|
||||
| ^^^^^^^^^^^^^^^^^ SIM910
|
||||
3 |
|
||||
4 | # SIM910
|
||||
|
|
||||
= help: Replace `{}.get(key, None)` with `{}.get(key)`
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | # SIM910
|
||||
2 |-{}.get(key, None)
|
||||
2 |+{}.get(key)
|
||||
3 3 |
|
||||
4 4 | # SIM910
|
||||
5 5 | {}.get("key", None)
|
||||
|
||||
SIM910.py:5:1: SIM910 [*] Use `{}.get("key")` instead of `{}.get("key", None)`
|
||||
|
|
||||
4 | # SIM910
|
||||
5 | {}.get("key", None)
|
||||
| ^^^^^^^^^^^^^^^^^^^ SIM910
|
||||
6 |
|
||||
7 | # OK
|
||||
|
|
||||
= help: Replace `{}.get("key", None)` with `{}.get("key")`
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 | {}.get(key, None)
|
||||
3 3 |
|
||||
4 4 | # SIM910
|
||||
5 |-{}.get("key", None)
|
||||
5 |+{}.get("key")
|
||||
6 6 |
|
||||
7 7 | # OK
|
||||
8 8 | {}.get(key)
|
||||
|
||||
SIM910.py:20:9: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)`
|
||||
|
|
||||
19 | # SIM910
|
||||
20 | if a := {}.get(key, None):
|
||||
| ^^^^^^^^^^^^^^^^^ SIM910
|
||||
21 | pass
|
||||
|
|
||||
= help: Replace `{}.get(key, None)` with `{}.get(key)`
|
||||
|
||||
ℹ Safe fix
|
||||
17 17 | {}.get("key", False)
|
||||
18 18 |
|
||||
19 19 | # SIM910
|
||||
20 |-if a := {}.get(key, None):
|
||||
20 |+if a := {}.get(key):
|
||||
21 21 | pass
|
||||
22 22 |
|
||||
23 23 | # SIM910
|
||||
|
||||
SIM910.py:24:5: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)`
|
||||
|
|
||||
23 | # SIM910
|
||||
24 | a = {}.get(key, None)
|
||||
| ^^^^^^^^^^^^^^^^^ SIM910
|
||||
25 |
|
||||
26 | # SIM910
|
||||
|
|
||||
= help: Replace `{}.get(key, None)` with `{}.get(key)`
|
||||
|
||||
ℹ Safe fix
|
||||
21 21 | pass
|
||||
22 22 |
|
||||
23 23 | # SIM910
|
||||
24 |-a = {}.get(key, None)
|
||||
24 |+a = {}.get(key)
|
||||
25 25 |
|
||||
26 26 | # SIM910
|
||||
27 27 | ({}).get(key, None)
|
||||
|
||||
SIM910.py:27:1: SIM910 [*] Use `({}).get(key)` instead of `({}).get(key, None)`
|
||||
|
|
||||
26 | # SIM910
|
||||
27 | ({}).get(key, None)
|
||||
| ^^^^^^^^^^^^^^^^^^^ SIM910
|
||||
28 |
|
||||
29 | # SIM910
|
||||
|
|
||||
= help: Replace `({}).get(key, None)` with `({}).get(key)`
|
||||
|
||||
ℹ Safe fix
|
||||
24 24 | a = {}.get(key, None)
|
||||
25 25 |
|
||||
26 26 | # SIM910
|
||||
27 |-({}).get(key, None)
|
||||
27 |+({}).get(key)
|
||||
28 28 |
|
||||
29 29 | # SIM910
|
||||
30 30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11}
|
||||
|
||||
SIM910.py:31:7: SIM910 [*] Use `ages.get("Cat")` instead of `ages.get("Cat", None)`
|
||||
|
|
||||
29 | # SIM910
|
||||
30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11}
|
||||
31 | age = ages.get("Cat", None)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ SIM910
|
||||
32 |
|
||||
33 | # OK
|
||||
|
|
||||
= help: Replace `ages.get("Cat", None)` with `ages.get("Cat")`
|
||||
|
||||
ℹ Safe fix
|
||||
28 28 |
|
||||
29 29 | # SIM910
|
||||
30 30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11}
|
||||
31 |-age = ages.get("Cat", None)
|
||||
31 |+age = ages.get("Cat")
|
||||
32 32 |
|
||||
33 33 | # OK
|
||||
34 34 | ages = ["Tom", "Maria", "Dog"]
|
||||
|
||||
|
|
@ -68,7 +68,6 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test_case(Rule::IsLiteral, Path::new("constant_literals.py"))]
|
||||
#[test_case(Rule::MultipleImportsOnOneLine, Path::new("E40.py"))]
|
||||
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_0.py"))]
|
||||
#[test_case(Rule::TypeComparison, Path::new("E721.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
|
|
|
@ -49,7 +49,6 @@ impl Violation for MultipleImportsOnOneLine {
|
|||
pub(crate) fn multiple_imports_on_one_line(checker: &mut Checker, stmt: &Stmt, names: &[Alias]) {
|
||||
if names.len() > 1 {
|
||||
let mut diagnostic = Diagnostic::new(MultipleImportsOnOneLine, stmt.range());
|
||||
if checker.settings.preview.is_enabled() {
|
||||
diagnostic.set_fix(split_imports(
|
||||
stmt,
|
||||
names,
|
||||
|
@ -57,7 +56,6 @@ pub(crate) fn multiple_imports_on_one_line(checker: &mut Checker, stmt: &Stmt, n
|
|||
checker.indexer(),
|
||||
checker.stylist(),
|
||||
));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
|
||||
---
|
||||
E40.py:2:1: E401 Multiple imports on one line
|
||||
E40.py:2:1: E401 [*] Multiple imports on one line
|
||||
|
|
||||
1 | #: E401
|
||||
2 | import os, sys
|
||||
|
@ -11,7 +11,16 @@ E40.py:2:1: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:65:1: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
1 1 | #: E401
|
||||
2 |-import os, sys
|
||||
2 |+import os
|
||||
3 |+import sys
|
||||
3 4 |
|
||||
4 5 | #: Okay
|
||||
5 6 | import os
|
||||
|
||||
E40.py:65:1: E401 [*] Multiple imports on one line
|
||||
|
|
||||
64 | #: E401
|
||||
65 | import re as regex, string # also with a comment!
|
||||
|
@ -20,7 +29,18 @@ E40.py:65:1: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:66:1: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
62 62 | import bar
|
||||
63 63 |
|
||||
64 64 | #: E401
|
||||
65 |-import re as regex, string # also with a comment!
|
||||
65 |+import re as regex
|
||||
66 |+import string # also with a comment!
|
||||
66 67 | import re as regex, string; x = 1
|
||||
67 68 |
|
||||
68 69 | x = 1; import re as regex, string
|
||||
|
||||
E40.py:66:1: E401 [*] Multiple imports on one line
|
||||
|
|
||||
64 | #: E401
|
||||
65 | import re as regex, string # also with a comment!
|
||||
|
@ -31,7 +51,17 @@ E40.py:66:1: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:68:8: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
63 63 |
|
||||
64 64 | #: E401
|
||||
65 65 | import re as regex, string # also with a comment!
|
||||
66 |-import re as regex, string; x = 1
|
||||
66 |+import re as regex; import string; x = 1
|
||||
67 67 |
|
||||
68 68 | x = 1; import re as regex, string
|
||||
69 69 |
|
||||
|
||||
E40.py:68:8: E401 [*] Multiple imports on one line
|
||||
|
|
||||
66 | import re as regex, string; x = 1
|
||||
67 |
|
||||
|
@ -40,7 +70,17 @@ E40.py:68:8: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:72:5: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
65 65 | import re as regex, string # also with a comment!
|
||||
66 66 | import re as regex, string; x = 1
|
||||
67 67 |
|
||||
68 |-x = 1; import re as regex, string
|
||||
68 |+x = 1; import re as regex; import string
|
||||
69 69 |
|
||||
70 70 |
|
||||
71 71 | def blah():
|
||||
|
||||
E40.py:72:5: E401 [*] Multiple imports on one line
|
||||
|
|
||||
71 | def blah():
|
||||
72 | import datetime as dt, copy
|
||||
|
@ -50,7 +90,18 @@ E40.py:72:5: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:75:9: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
69 69 |
|
||||
70 70 |
|
||||
71 71 | def blah():
|
||||
72 |- import datetime as dt, copy
|
||||
72 |+ import datetime as dt
|
||||
73 |+ import copy
|
||||
73 74 |
|
||||
74 75 | def nested_and_tested():
|
||||
75 76 | import builtins, textwrap as tw
|
||||
|
||||
E40.py:75:9: E401 [*] Multiple imports on one line
|
||||
|
|
||||
74 | def nested_and_tested():
|
||||
75 | import builtins, textwrap as tw
|
||||
|
@ -60,7 +111,18 @@ E40.py:75:9: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:77:16: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
72 72 | import datetime as dt, copy
|
||||
73 73 |
|
||||
74 74 | def nested_and_tested():
|
||||
75 |- import builtins, textwrap as tw
|
||||
75 |+ import builtins
|
||||
76 |+ import textwrap as tw
|
||||
76 77 |
|
||||
77 78 | x = 1; import re as regex, string
|
||||
78 79 | import re as regex, string; x = 1
|
||||
|
||||
E40.py:77:16: E401 [*] Multiple imports on one line
|
||||
|
|
||||
75 | import builtins, textwrap as tw
|
||||
76 |
|
||||
|
@ -70,7 +132,17 @@ E40.py:77:16: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:78:9: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
74 74 | def nested_and_tested():
|
||||
75 75 | import builtins, textwrap as tw
|
||||
76 76 |
|
||||
77 |- x = 1; import re as regex, string
|
||||
77 |+ x = 1; import re as regex; import string
|
||||
78 78 | import re as regex, string; x = 1
|
||||
79 79 |
|
||||
80 80 | if True: import re as regex, string
|
||||
|
||||
E40.py:78:9: E401 [*] Multiple imports on one line
|
||||
|
|
||||
77 | x = 1; import re as regex, string
|
||||
78 | import re as regex, string; x = 1
|
||||
|
@ -80,7 +152,16 @@ E40.py:78:9: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
E40.py:80:14: E401 Multiple imports on one line
|
||||
ℹ Safe fix
|
||||
75 75 | import builtins, textwrap as tw
|
||||
76 76 |
|
||||
77 77 | x = 1; import re as regex, string
|
||||
78 |- import re as regex, string; x = 1
|
||||
78 |+ import re as regex; import string; x = 1
|
||||
79 79 |
|
||||
80 80 | if True: import re as regex, string
|
||||
|
||||
E40.py:80:14: E401 [*] Multiple imports on one line
|
||||
|
|
||||
78 | import re as regex, string; x = 1
|
||||
79 |
|
||||
|
@ -89,4 +170,11 @@ E40.py:80:14: E401 Multiple imports on one line
|
|||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
77 77 | x = 1; import re as regex, string
|
||||
78 78 | import re as regex, string; x = 1
|
||||
79 79 |
|
||||
80 |- if True: import re as regex, string
|
||||
80 |+ if True: import re as regex; import string
|
||||
|
||||
|
||||
|
|
|
@ -1,180 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
|
||||
---
|
||||
E40.py:2:1: E401 [*] Multiple imports on one line
|
||||
|
|
||||
1 | #: E401
|
||||
2 | import os, sys
|
||||
| ^^^^^^^^^^^^^^ E401
|
||||
3 |
|
||||
4 | #: Okay
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | #: E401
|
||||
2 |-import os, sys
|
||||
2 |+import os
|
||||
3 |+import sys
|
||||
3 4 |
|
||||
4 5 | #: Okay
|
||||
5 6 | import os
|
||||
|
||||
E40.py:65:1: E401 [*] Multiple imports on one line
|
||||
|
|
||||
64 | #: E401
|
||||
65 | import re as regex, string # also with a comment!
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
66 | import re as regex, string; x = 1
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
62 62 | import bar
|
||||
63 63 |
|
||||
64 64 | #: E401
|
||||
65 |-import re as regex, string # also with a comment!
|
||||
65 |+import re as regex
|
||||
66 |+import string # also with a comment!
|
||||
66 67 | import re as regex, string; x = 1
|
||||
67 68 |
|
||||
68 69 | x = 1; import re as regex, string
|
||||
|
||||
E40.py:66:1: E401 [*] Multiple imports on one line
|
||||
|
|
||||
64 | #: E401
|
||||
65 | import re as regex, string # also with a comment!
|
||||
66 | import re as regex, string; x = 1
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
67 |
|
||||
68 | x = 1; import re as regex, string
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
63 63 |
|
||||
64 64 | #: E401
|
||||
65 65 | import re as regex, string # also with a comment!
|
||||
66 |-import re as regex, string; x = 1
|
||||
66 |+import re as regex; import string; x = 1
|
||||
67 67 |
|
||||
68 68 | x = 1; import re as regex, string
|
||||
69 69 |
|
||||
|
||||
E40.py:68:8: E401 [*] Multiple imports on one line
|
||||
|
|
||||
66 | import re as regex, string; x = 1
|
||||
67 |
|
||||
68 | x = 1; import re as regex, string
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
65 65 | import re as regex, string # also with a comment!
|
||||
66 66 | import re as regex, string; x = 1
|
||||
67 67 |
|
||||
68 |-x = 1; import re as regex, string
|
||||
68 |+x = 1; import re as regex; import string
|
||||
69 69 |
|
||||
70 70 |
|
||||
71 71 | def blah():
|
||||
|
||||
E40.py:72:5: E401 [*] Multiple imports on one line
|
||||
|
|
||||
71 | def blah():
|
||||
72 | import datetime as dt, copy
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
73 |
|
||||
74 | def nested_and_tested():
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
69 69 |
|
||||
70 70 |
|
||||
71 71 | def blah():
|
||||
72 |- import datetime as dt, copy
|
||||
72 |+ import datetime as dt
|
||||
73 |+ import copy
|
||||
73 74 |
|
||||
74 75 | def nested_and_tested():
|
||||
75 76 | import builtins, textwrap as tw
|
||||
|
||||
E40.py:75:9: E401 [*] Multiple imports on one line
|
||||
|
|
||||
74 | def nested_and_tested():
|
||||
75 | import builtins, textwrap as tw
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
76 |
|
||||
77 | x = 1; import re as regex, string
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
72 72 | import datetime as dt, copy
|
||||
73 73 |
|
||||
74 74 | def nested_and_tested():
|
||||
75 |- import builtins, textwrap as tw
|
||||
75 |+ import builtins
|
||||
76 |+ import textwrap as tw
|
||||
76 77 |
|
||||
77 78 | x = 1; import re as regex, string
|
||||
78 79 | import re as regex, string; x = 1
|
||||
|
||||
E40.py:77:16: E401 [*] Multiple imports on one line
|
||||
|
|
||||
75 | import builtins, textwrap as tw
|
||||
76 |
|
||||
77 | x = 1; import re as regex, string
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
78 | import re as regex, string; x = 1
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
74 74 | def nested_and_tested():
|
||||
75 75 | import builtins, textwrap as tw
|
||||
76 76 |
|
||||
77 |- x = 1; import re as regex, string
|
||||
77 |+ x = 1; import re as regex; import string
|
||||
78 78 | import re as regex, string; x = 1
|
||||
79 79 |
|
||||
80 80 | if True: import re as regex, string
|
||||
|
||||
E40.py:78:9: E401 [*] Multiple imports on one line
|
||||
|
|
||||
77 | x = 1; import re as regex, string
|
||||
78 | import re as regex, string; x = 1
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
79 |
|
||||
80 | if True: import re as regex, string
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
75 75 | import builtins, textwrap as tw
|
||||
76 76 |
|
||||
77 77 | x = 1; import re as regex, string
|
||||
78 |- import re as regex, string; x = 1
|
||||
78 |+ import re as regex; import string; x = 1
|
||||
79 79 |
|
||||
80 80 | if True: import re as regex, string
|
||||
|
||||
E40.py:80:14: E401 [*] Multiple imports on one line
|
||||
|
|
||||
78 | import re as regex, string; x = 1
|
||||
79 |
|
||||
80 | if True: import re as regex, string
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ E401
|
||||
|
|
||||
= help: Split imports
|
||||
|
||||
ℹ Safe fix
|
||||
77 77 | x = 1; import re as regex, string
|
||||
78 78 | import re as regex, string; x = 1
|
||||
79 79 |
|
||||
80 |- if True: import re as regex, string
|
||||
80 |+ if True: import re as regex; import string
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ mod tests {
|
|||
use test_case::test_case;
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::types::PreviewMode;
|
||||
|
||||
use crate::test::test_path;
|
||||
use crate::{assert_messages, settings};
|
||||
|
||||
|
@ -111,33 +111,6 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::TripleSingleQuotes, Path::new("D.py"))]
|
||||
#[test_case(Rule::TripleSingleQuotes, Path::new("D300.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
// Tests for rules with preview features
|
||||
let snapshot = format!(
|
||||
"preview__{}_{}",
|
||||
rule_code.noqa_code(),
|
||||
path.to_string_lossy()
|
||||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("pydocstyle").join(path).as_path(),
|
||||
&settings::LinterSettings {
|
||||
pydocstyle: Settings {
|
||||
convention: None,
|
||||
ignore_decorators: BTreeSet::from_iter(["functools.wraps".to_string()]),
|
||||
property_decorators: BTreeSet::from_iter([
|
||||
"gi.repository.GObject.Property".to_string()
|
||||
]),
|
||||
},
|
||||
preview: PreviewMode::Enabled,
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bom() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
|
|
|
@ -80,7 +80,6 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(TripleSingleQuotes { expected_quote }, docstring.range());
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
let body = docstring.body().as_str();
|
||||
if !body.ends_with('\'') {
|
||||
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
|
||||
|
@ -88,7 +87,6 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
|
|||
docstring.range(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -98,7 +96,6 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(TripleSingleQuotes { expected_quote }, docstring.range());
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
let body = docstring.body().as_str();
|
||||
if !body.ends_with('"') {
|
||||
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
|
||||
|
@ -106,7 +103,6 @@ pub(crate) fn triple_quotes(checker: &mut Checker, docstring: &Docstring) {
|
|||
docstring.range(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
|
||||
---
|
||||
D.py:307:5: D300 Use triple double quotes `"""`
|
||||
D.py:307:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
305 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
306 | def triple_single_quotes_raw():
|
||||
|
@ -10,7 +10,17 @@ D.py:307:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:312:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
304 304 |
|
||||
305 305 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
306 306 | def triple_single_quotes_raw():
|
||||
307 |- r'''Summary.'''
|
||||
307 |+ r"""Summary."""
|
||||
308 308 |
|
||||
309 309 |
|
||||
310 310 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
|
||||
D.py:312:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
310 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
311 | def triple_single_quotes_raw_uppercase():
|
||||
|
@ -19,7 +29,17 @@ D.py:312:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:317:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
309 309 |
|
||||
310 310 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
311 311 | def triple_single_quotes_raw_uppercase():
|
||||
312 |- R'''Summary.'''
|
||||
312 |+ R"""Summary."""
|
||||
313 313 |
|
||||
314 314 |
|
||||
315 315 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
|
||||
D.py:317:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
315 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
316 | def single_quotes_raw():
|
||||
|
@ -28,7 +48,17 @@ D.py:317:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:322:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
314 314 |
|
||||
315 315 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
316 316 | def single_quotes_raw():
|
||||
317 |- r'Summary.'
|
||||
317 |+ r"""Summary."""
|
||||
318 318 |
|
||||
319 319 |
|
||||
320 320 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
|
||||
D.py:322:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
320 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
321 | def single_quotes_raw_uppercase():
|
||||
|
@ -37,7 +67,17 @@ D.py:322:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:328:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
319 319 |
|
||||
320 320 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
321 321 | def single_quotes_raw_uppercase():
|
||||
322 |- R'Summary.'
|
||||
322 |+ R"""Summary."""
|
||||
323 323 |
|
||||
324 324 |
|
||||
325 325 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
|
||||
D.py:328:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
326 | @expect('D301: Use r""" if any backslashes in a docstring')
|
||||
327 | def single_quotes_raw_uppercase_backslash():
|
||||
|
@ -46,7 +86,17 @@ D.py:328:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:645:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
325 325 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
326 326 | @expect('D301: Use r""" if any backslashes in a docstring')
|
||||
327 327 | def single_quotes_raw_uppercase_backslash():
|
||||
328 |- R'Sum\mary.'
|
||||
328 |+ R"""Sum\mary."""
|
||||
329 329 |
|
||||
330 330 |
|
||||
331 331 | @expect('D301: Use r""" if any backslashes in a docstring')
|
||||
|
||||
D.py:645:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
644 | def single_line_docstring_with_an_escaped_backslash():
|
||||
645 | "\
|
||||
|
@ -58,7 +108,19 @@ D.py:645:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:649:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
642 642 |
|
||||
643 643 |
|
||||
644 644 | def single_line_docstring_with_an_escaped_backslash():
|
||||
645 |- "\
|
||||
646 |- "
|
||||
645 |+ """\
|
||||
646 |+ """
|
||||
647 647 |
|
||||
648 648 | class StatementOnSameLineAsDocstring:
|
||||
649 649 | "After this docstring there's another statement on the same line separated by a semicolon." ; priorities=1
|
||||
|
||||
D.py:649:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
648 | class StatementOnSameLineAsDocstring:
|
||||
649 | "After this docstring there's another statement on the same line separated by a semicolon." ; priorities=1
|
||||
|
@ -68,7 +130,17 @@ D.py:649:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:654:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
646 646 | "
|
||||
647 647 |
|
||||
648 648 | class StatementOnSameLineAsDocstring:
|
||||
649 |- "After this docstring there's another statement on the same line separated by a semicolon." ; priorities=1
|
||||
649 |+ """After this docstring there's another statement on the same line separated by a semicolon.""" ; priorities=1
|
||||
650 650 | def sort_services(self):
|
||||
651 651 | pass
|
||||
652 652 |
|
||||
|
||||
D.py:654:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
653 | class StatementOnSameLineAsDocstring:
|
||||
654 | "After this docstring there's another statement on the same line separated by a semicolon."; priorities=1
|
||||
|
@ -76,7 +148,17 @@ D.py:654:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:658:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
651 651 | pass
|
||||
652 652 |
|
||||
653 653 | class StatementOnSameLineAsDocstring:
|
||||
654 |- "After this docstring there's another statement on the same line separated by a semicolon."; priorities=1
|
||||
654 |+ """After this docstring there's another statement on the same line separated by a semicolon."""; priorities=1
|
||||
655 655 |
|
||||
656 656 |
|
||||
657 657 | class CommentAfterDocstring:
|
||||
|
||||
D.py:658:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
657 | class CommentAfterDocstring:
|
||||
658 | "After this docstring there's a comment." # priorities=1
|
||||
|
@ -86,7 +168,17 @@ D.py:658:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D.py:664:5: D300 Use triple double quotes `"""`
|
||||
ℹ Safe fix
|
||||
655 655 |
|
||||
656 656 |
|
||||
657 657 | class CommentAfterDocstring:
|
||||
658 |- "After this docstring there's a comment." # priorities=1
|
||||
658 |+ """After this docstring there's a comment.""" # priorities=1
|
||||
659 659 | def sort_services(self):
|
||||
660 660 | pass
|
||||
661 661 |
|
||||
|
||||
D.py:664:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
663 | def newline_after_closing_quote(self):
|
||||
664 | "We enforce a newline after the closing quote for a multi-line docstring \
|
||||
|
@ -96,4 +188,16 @@ D.py:664:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
661 661 |
|
||||
662 662 |
|
||||
663 663 | def newline_after_closing_quote(self):
|
||||
664 |- "We enforce a newline after the closing quote for a multi-line docstring \
|
||||
665 |- but continuations shouldn't be considered multi-line"
|
||||
664 |+ """We enforce a newline after the closing quote for a multi-line docstring \
|
||||
665 |+ but continuations shouldn't be considered multi-line"""
|
||||
666 666 |
|
||||
667 667 |
|
||||
668 668 |
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ D300.py:6:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D300.py:10:5: D300 Use triple double quotes `"""`
|
||||
D300.py:10:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
9 | def contains_quote():
|
||||
10 | 'Sum"\\mary.'
|
||||
|
@ -17,4 +17,14 @@ D300.py:10:5: D300 Use triple double quotes `"""`
|
|||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
7 7 |
|
||||
8 8 |
|
||||
9 9 | def contains_quote():
|
||||
10 |- 'Sum"\\mary.'
|
||||
10 |+ """Sum"\\mary."""
|
||||
11 11 |
|
||||
12 12 |
|
||||
13 13 | # OK
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
|
||||
---
|
||||
bom.py:1:1: D300 Use triple double quotes `"""`
|
||||
bom.py:1:1: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
1 | ''' SAM macro definitions '''
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
1 |-''' SAM macro definitions '''
|
||||
1 |+""" SAM macro definitions """
|
||||
|
||||
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
|
||||
---
|
||||
D.py:307:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
305 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
306 | def triple_single_quotes_raw():
|
||||
307 | r'''Summary.'''
|
||||
| ^^^^^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
304 304 |
|
||||
305 305 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
306 306 | def triple_single_quotes_raw():
|
||||
307 |- r'''Summary.'''
|
||||
307 |+ r"""Summary."""
|
||||
308 308 |
|
||||
309 309 |
|
||||
310 310 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
|
||||
D.py:312:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
310 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
311 | def triple_single_quotes_raw_uppercase():
|
||||
312 | R'''Summary.'''
|
||||
| ^^^^^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
309 309 |
|
||||
310 310 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
|
||||
311 311 | def triple_single_quotes_raw_uppercase():
|
||||
312 |- R'''Summary.'''
|
||||
312 |+ R"""Summary."""
|
||||
313 313 |
|
||||
314 314 |
|
||||
315 315 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
|
||||
D.py:317:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
315 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
316 | def single_quotes_raw():
|
||||
317 | r'Summary.'
|
||||
| ^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
314 314 |
|
||||
315 315 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
316 316 | def single_quotes_raw():
|
||||
317 |- r'Summary.'
|
||||
317 |+ r"""Summary."""
|
||||
318 318 |
|
||||
319 319 |
|
||||
320 320 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
|
||||
D.py:322:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
320 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
321 | def single_quotes_raw_uppercase():
|
||||
322 | R'Summary.'
|
||||
| ^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
319 319 |
|
||||
320 320 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
321 321 | def single_quotes_raw_uppercase():
|
||||
322 |- R'Summary.'
|
||||
322 |+ R"""Summary."""
|
||||
323 323 |
|
||||
324 324 |
|
||||
325 325 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
|
||||
D.py:328:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
326 | @expect('D301: Use r""" if any backslashes in a docstring')
|
||||
327 | def single_quotes_raw_uppercase_backslash():
|
||||
328 | R'Sum\mary.'
|
||||
| ^^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
325 325 | @expect('D300: Use """triple double quotes""" (found \'-quotes)')
|
||||
326 326 | @expect('D301: Use r""" if any backslashes in a docstring')
|
||||
327 327 | def single_quotes_raw_uppercase_backslash():
|
||||
328 |- R'Sum\mary.'
|
||||
328 |+ R"""Sum\mary."""
|
||||
329 329 |
|
||||
330 330 |
|
||||
331 331 | @expect('D301: Use r""" if any backslashes in a docstring')
|
||||
|
||||
D.py:645:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
644 | def single_line_docstring_with_an_escaped_backslash():
|
||||
645 | "\
|
||||
| _____^
|
||||
646 | | "
|
||||
| |_____^ D300
|
||||
647 |
|
||||
648 | class StatementOnSameLineAsDocstring:
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
642 642 |
|
||||
643 643 |
|
||||
644 644 | def single_line_docstring_with_an_escaped_backslash():
|
||||
645 |- "\
|
||||
646 |- "
|
||||
645 |+ """\
|
||||
646 |+ """
|
||||
647 647 |
|
||||
648 648 | class StatementOnSameLineAsDocstring:
|
||||
649 649 | "After this docstring there's another statement on the same line separated by a semicolon." ; priorities=1
|
||||
|
||||
D.py:649:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
648 | class StatementOnSameLineAsDocstring:
|
||||
649 | "After this docstring there's another statement on the same line separated by a semicolon." ; priorities=1
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D300
|
||||
650 | def sort_services(self):
|
||||
651 | pass
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
646 646 | "
|
||||
647 647 |
|
||||
648 648 | class StatementOnSameLineAsDocstring:
|
||||
649 |- "After this docstring there's another statement on the same line separated by a semicolon." ; priorities=1
|
||||
649 |+ """After this docstring there's another statement on the same line separated by a semicolon.""" ; priorities=1
|
||||
650 650 | def sort_services(self):
|
||||
651 651 | pass
|
||||
652 652 |
|
||||
|
||||
D.py:654:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
653 | class StatementOnSameLineAsDocstring:
|
||||
654 | "After this docstring there's another statement on the same line separated by a semicolon."; priorities=1
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
651 651 | pass
|
||||
652 652 |
|
||||
653 653 | class StatementOnSameLineAsDocstring:
|
||||
654 |- "After this docstring there's another statement on the same line separated by a semicolon."; priorities=1
|
||||
654 |+ """After this docstring there's another statement on the same line separated by a semicolon."""; priorities=1
|
||||
655 655 |
|
||||
656 656 |
|
||||
657 657 | class CommentAfterDocstring:
|
||||
|
||||
D.py:658:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
657 | class CommentAfterDocstring:
|
||||
658 | "After this docstring there's a comment." # priorities=1
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D300
|
||||
659 | def sort_services(self):
|
||||
660 | pass
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
655 655 |
|
||||
656 656 |
|
||||
657 657 | class CommentAfterDocstring:
|
||||
658 |- "After this docstring there's a comment." # priorities=1
|
||||
658 |+ """After this docstring there's a comment.""" # priorities=1
|
||||
659 659 | def sort_services(self):
|
||||
660 660 | pass
|
||||
661 661 |
|
||||
|
||||
D.py:664:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
663 | def newline_after_closing_quote(self):
|
||||
664 | "We enforce a newline after the closing quote for a multi-line docstring \
|
||||
| _____^
|
||||
665 | | but continuations shouldn't be considered multi-line"
|
||||
| |_________________________________________________________^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
661 661 |
|
||||
662 662 |
|
||||
663 663 | def newline_after_closing_quote(self):
|
||||
664 |- "We enforce a newline after the closing quote for a multi-line docstring \
|
||||
665 |- but continuations shouldn't be considered multi-line"
|
||||
664 |+ """We enforce a newline after the closing quote for a multi-line docstring \
|
||||
665 |+ but continuations shouldn't be considered multi-line"""
|
||||
666 666 |
|
||||
667 667 |
|
||||
668 668 |
|
||||
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
|
||||
---
|
||||
D300.py:6:5: D300 Use triple double quotes `"""`
|
||||
|
|
||||
5 | def ends_in_quote():
|
||||
6 | 'Sum\\mary."'
|
||||
| ^^^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
D300.py:10:5: D300 [*] Use triple double quotes `"""`
|
||||
|
|
||||
9 | def contains_quote():
|
||||
10 | 'Sum"\\mary.'
|
||||
| ^^^^^^^^^^^^^ D300
|
||||
|
|
||||
= help: Convert to triple double quotes
|
||||
|
||||
ℹ Safe fix
|
||||
7 7 |
|
||||
8 8 |
|
||||
9 9 | def contains_quote():
|
||||
10 |- 'Sum"\\mary.'
|
||||
10 |+ """Sum"\\mary."""
|
||||
11 11 |
|
||||
12 12 |
|
||||
13 13 | # OK
|
||||
|
||||
|
|
@ -170,34 +170,6 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_0.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_1.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_10.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_11.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_12.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_13.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_14.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_15.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_16.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_17.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_18.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_19.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_2.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_20.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_21.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_22.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_23.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_24.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_25.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_26.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_27.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_3.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_4.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_5.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_6.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_7.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_8.py"))]
|
||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_9.py"))]
|
||||
#[test_case(Rule::UnusedVariable, Path::new("F841_4.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_1.py:1:25: F811 Redefinition of unused `FU` from line 1
|
||||
F811_1.py:1:25: F811 [*] Redefinition of unused `FU` from line 1
|
||||
|
|
||||
1 | import fu as FU, bar as FU
|
||||
| ^^ F811
|
||||
|
|
||||
= help: Remove definition: `FU`
|
||||
|
||||
ℹ Safe fix
|
||||
1 |-import fu as FU, bar as FU
|
||||
1 |+import fu as FU
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_12.py:6:20: F811 Redefinition of unused `mixer` from line 2
|
||||
F811_12.py:6:20: F811 [*] Redefinition of unused `mixer` from line 2
|
||||
|
|
||||
4 | pass
|
||||
5 | else:
|
||||
|
@ -11,4 +11,12 @@ F811_12.py:6:20: F811 Redefinition of unused `mixer` from line 2
|
|||
|
|
||||
= help: Remove definition: `mixer`
|
||||
|
||||
ℹ Safe fix
|
||||
3 3 | except ImportError:
|
||||
4 4 | pass
|
||||
5 5 | else:
|
||||
6 |- from bb import mixer
|
||||
6 |+ pass
|
||||
7 7 | mixer(123)
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_17.py:6:12: F811 Redefinition of unused `fu` from line 2
|
||||
F811_17.py:6:12: F811 [*] Redefinition of unused `fu` from line 2
|
||||
|
|
||||
5 | def bar():
|
||||
6 | import fu
|
||||
|
@ -11,6 +11,15 @@ F811_17.py:6:12: F811 Redefinition of unused `fu` from line 2
|
|||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
ℹ Safe fix
|
||||
3 3 |
|
||||
4 4 |
|
||||
5 5 | def bar():
|
||||
6 |- import fu
|
||||
7 6 |
|
||||
8 7 | def baz():
|
||||
9 8 | def fu():
|
||||
|
||||
F811_17.py:9:13: F811 Redefinition of unused `fu` from line 6
|
||||
|
|
||||
8 | def baz():
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_2.py:1:34: F811 Redefinition of unused `FU` from line 1
|
||||
F811_2.py:1:34: F811 [*] Redefinition of unused `FU` from line 1
|
||||
|
|
||||
1 | from moo import fu as FU, bar as FU
|
||||
| ^^ F811
|
||||
|
|
||||
= help: Remove definition: `FU`
|
||||
|
||||
ℹ Safe fix
|
||||
1 |-from moo import fu as FU, bar as FU
|
||||
1 |+from moo import fu as FU
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_21.py:32:5: F811 Redefinition of unused `Sequence` from line 26
|
||||
F811_21.py:32:5: F811 [*] Redefinition of unused `Sequence` from line 26
|
||||
|
|
||||
30 | from typing import (
|
||||
31 | List, # noqa: F811
|
||||
|
@ -11,4 +11,15 @@ F811_21.py:32:5: F811 Redefinition of unused `Sequence` from line 26
|
|||
|
|
||||
= help: Remove definition: `Sequence`
|
||||
|
||||
ℹ Safe fix
|
||||
29 29 | # This should ignore the first error.
|
||||
30 30 | from typing import (
|
||||
31 31 | List, # noqa: F811
|
||||
32 |- Sequence,
|
||||
33 |-)
|
||||
32 |+ )
|
||||
34 33 |
|
||||
35 34 | # This should ignore both errors.
|
||||
36 35 | from typing import ( # noqa
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_23.py:4:15: F811 Redefinition of unused `foo` from line 3
|
||||
F811_23.py:4:15: F811 [*] Redefinition of unused `foo` from line 3
|
||||
|
|
||||
3 | import foo as foo
|
||||
4 | import bar as foo
|
||||
|
@ -9,4 +9,10 @@ F811_23.py:4:15: F811 Redefinition of unused `foo` from line 3
|
|||
|
|
||||
= help: Remove definition: `foo`
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | """Test that shadowing an explicit re-export produces a warning."""
|
||||
2 2 |
|
||||
3 3 | import foo as foo
|
||||
4 |-import bar as foo
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_6.py:6:12: F811 Redefinition of unused `os` from line 5
|
||||
F811_6.py:6:12: F811 [*] Redefinition of unused `os` from line 5
|
||||
|
|
||||
4 | if i == 1:
|
||||
5 | import os
|
||||
|
@ -11,4 +11,11 @@ F811_6.py:6:12: F811 Redefinition of unused `os` from line 5
|
|||
|
|
||||
= help: Remove definition: `os`
|
||||
|
||||
ℹ Safe fix
|
||||
3 3 | i = 2
|
||||
4 4 | if i == 1:
|
||||
5 5 | import os
|
||||
6 |- import os
|
||||
7 6 | os.path
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_8.py:5:12: F811 Redefinition of unused `os` from line 4
|
||||
F811_8.py:5:12: F811 [*] Redefinition of unused `os` from line 4
|
||||
|
|
||||
3 | try:
|
||||
4 | import os
|
||||
|
@ -12,4 +12,13 @@ F811_8.py:5:12: F811 Redefinition of unused `os` from line 4
|
|||
|
|
||||
= help: Remove definition: `os`
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 |
|
||||
3 3 | try:
|
||||
4 4 | import os
|
||||
5 |- import os
|
||||
6 5 | except:
|
||||
7 6 | pass
|
||||
8 7 | os.path
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
|||
4 3 | def f():
|
||||
5 4 | import os
|
||||
|
||||
<filename>:5:12: F811 Redefinition of unused `os` from line 2
|
||||
<filename>:5:12: F811 [*] Redefinition of unused `os` from line 2
|
||||
|
|
||||
4 | def f():
|
||||
5 | import os
|
||||
|
@ -27,4 +27,13 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
|||
|
|
||||
= help: Remove definition: `os`
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 | import os
|
||||
3 3 |
|
||||
4 4 | def f():
|
||||
5 |- import os
|
||||
6 5 |
|
||||
7 6 | # Despite this `del`, `import os` in `f` should still be flagged as shadowing an unused
|
||||
8 7 | # import.
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
<filename>:4:12: F811 Redefinition of unused `os` from line 3
|
||||
<filename>:4:12: F811 [*] Redefinition of unused `os` from line 3
|
||||
|
|
||||
2 | def f():
|
||||
3 | import os
|
||||
|
@ -12,4 +12,13 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
|||
|
|
||||
= help: Remove definition: `os`
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 |
|
||||
2 2 | def f():
|
||||
3 3 | import os
|
||||
4 |- import os
|
||||
5 4 |
|
||||
6 5 | # Despite this `del`, `import os` should still be flagged as shadowing an unused
|
||||
7 6 | # import.
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_0.py:10:5: F811 Redefinition of unused `bar` from line 6
|
||||
|
|
||||
10 | def bar():
|
||||
| ^^^ F811
|
||||
11 | pass
|
||||
|
|
||||
= help: Remove definition: `bar`
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_1.py:1:25: F811 [*] Redefinition of unused `FU` from line 1
|
||||
|
|
||||
1 | import fu as FU, bar as FU
|
||||
| ^^ F811
|
||||
|
|
||||
= help: Remove definition: `FU`
|
||||
|
||||
ℹ Safe fix
|
||||
1 |-import fu as FU, bar as FU
|
||||
1 |+import fu as FU
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_12.py:6:20: F811 [*] Redefinition of unused `mixer` from line 2
|
||||
|
|
||||
4 | pass
|
||||
5 | else:
|
||||
6 | from bb import mixer
|
||||
| ^^^^^ F811
|
||||
7 | mixer(123)
|
||||
|
|
||||
= help: Remove definition: `mixer`
|
||||
|
||||
ℹ Safe fix
|
||||
3 3 | except ImportError:
|
||||
4 4 | pass
|
||||
5 5 | else:
|
||||
6 |- from bb import mixer
|
||||
6 |+ pass
|
||||
7 7 | mixer(123)
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_15.py:4:5: F811 Redefinition of unused `fu` from line 1
|
||||
|
|
||||
4 | def fu():
|
||||
| ^^ F811
|
||||
5 | pass
|
||||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_16.py:8:13: F811 Redefinition of unused `fu` from line 3
|
||||
|
|
||||
6 | def bar():
|
||||
7 | def baz():
|
||||
8 | def fu():
|
||||
| ^^ F811
|
||||
9 | pass
|
||||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_17.py:6:12: F811 [*] Redefinition of unused `fu` from line 2
|
||||
|
|
||||
5 | def bar():
|
||||
6 | import fu
|
||||
| ^^ F811
|
||||
7 |
|
||||
8 | def baz():
|
||||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
ℹ Safe fix
|
||||
3 3 |
|
||||
4 4 |
|
||||
5 5 | def bar():
|
||||
6 |- import fu
|
||||
7 6 |
|
||||
8 7 | def baz():
|
||||
9 8 | def fu():
|
||||
|
||||
F811_17.py:9:13: F811 Redefinition of unused `fu` from line 6
|
||||
|
|
||||
8 | def baz():
|
||||
9 | def fu():
|
||||
| ^^ F811
|
||||
10 | pass
|
||||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_2.py:1:34: F811 [*] Redefinition of unused `FU` from line 1
|
||||
|
|
||||
1 | from moo import fu as FU, bar as FU
|
||||
| ^^ F811
|
||||
|
|
||||
= help: Remove definition: `FU`
|
||||
|
||||
ℹ Safe fix
|
||||
1 |-from moo import fu as FU, bar as FU
|
||||
1 |+from moo import fu as FU
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_21.py:32:5: F811 [*] Redefinition of unused `Sequence` from line 26
|
||||
|
|
||||
30 | from typing import (
|
||||
31 | List, # noqa: F811
|
||||
32 | Sequence,
|
||||
| ^^^^^^^^ F811
|
||||
33 | )
|
||||
|
|
||||
= help: Remove definition: `Sequence`
|
||||
|
||||
ℹ Safe fix
|
||||
29 29 | # This should ignore the first error.
|
||||
30 30 | from typing import (
|
||||
31 31 | List, # noqa: F811
|
||||
32 |- Sequence,
|
||||
33 |-)
|
||||
32 |+ )
|
||||
34 33 |
|
||||
35 34 | # This should ignore both errors.
|
||||
36 35 | from typing import ( # noqa
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_23.py:4:15: F811 [*] Redefinition of unused `foo` from line 3
|
||||
|
|
||||
3 | import foo as foo
|
||||
4 | import bar as foo
|
||||
| ^^^ F811
|
||||
|
|
||||
= help: Remove definition: `foo`
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | """Test that shadowing an explicit re-export produces a warning."""
|
||||
2 2 |
|
||||
3 3 | import foo as foo
|
||||
4 |-import bar as foo
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_26.py:5:9: F811 Redefinition of unused `func` from line 2
|
||||
|
|
||||
3 | pass
|
||||
4 |
|
||||
5 | def func(self):
|
||||
| ^^^^ F811
|
||||
6 | pass
|
||||
|
|
||||
= help: Remove definition: `func`
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_3.py:1:12: F811 Redefinition of unused `fu` from line 1
|
||||
|
|
||||
1 | import fu; fu = 3
|
||||
| ^^ F811
|
||||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_4.py:1:12: F811 Redefinition of unused `fu` from line 1
|
||||
|
|
||||
1 | import fu; fu, bar = 3
|
||||
| ^^ F811
|
||||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_5.py:1:13: F811 Redefinition of unused `fu` from line 1
|
||||
|
|
||||
1 | import fu; [fu, bar] = 3
|
||||
| ^^ F811
|
||||
|
|
||||
= help: Remove definition: `fu`
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_6.py:6:12: F811 [*] Redefinition of unused `os` from line 5
|
||||
|
|
||||
4 | if i == 1:
|
||||
5 | import os
|
||||
6 | import os
|
||||
| ^^ F811
|
||||
7 | os.path
|
||||
|
|
||||
= help: Remove definition: `os`
|
||||
|
||||
ℹ Safe fix
|
||||
3 3 | i = 2
|
||||
4 4 | if i == 1:
|
||||
5 5 | import os
|
||||
6 |- import os
|
||||
7 6 | os.path
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
F811_8.py:5:12: F811 [*] Redefinition of unused `os` from line 4
|
||||
|
|
||||
3 | try:
|
||||
4 | import os
|
||||
5 | import os
|
||||
| ^^ F811
|
||||
6 | except:
|
||||
7 | pass
|
||||
|
|
||||
= help: Remove definition: `os`
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 |
|
||||
3 3 | try:
|
||||
4 4 | import os
|
||||
5 |- import os
|
||||
6 5 | except:
|
||||
7 6 | pass
|
||||
8 7 | os.path
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
|
||||
---
|
||||
|
|
@ -9,8 +9,7 @@ mod tests {
|
|||
use test_case::test_case;
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::types::PreviewMode;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
use crate::test::test_path;
|
||||
use crate::{assert_messages, settings};
|
||||
|
||||
|
@ -31,22 +30,4 @@ mod tests {
|
|||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::DeprecatedLogWarn, Path::new("PGH002_1.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
"preview__{}_{}",
|
||||
rule_code.noqa_code(),
|
||||
path.to_string_lossy()
|
||||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("pygrep_hooks").join(path).as_path(),
|
||||
&LinterSettings {
|
||||
preview: PreviewMode::Enabled,
|
||||
..LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ pub(crate) fn deprecated_log_warn(checker: &mut Checker, call: &ast::ExprCall) {
|
|||
}
|
||||
|
||||
let mut diagnostic = Diagnostic::new(DeprecatedLogWarn, call.func.range());
|
||||
if checker.settings.preview.is_enabled() {
|
||||
|
||||
match call.func.as_ref() {
|
||||
Expr::Attribute(ast::ExprAttribute { attr, .. }) => {
|
||||
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
|
||||
|
@ -102,6 +102,6 @@ pub(crate) fn deprecated_log_warn(checker: &mut Checker, call: &ast::ExprCall) {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pygrep_hooks/mod.rs
|
||||
---
|
||||
PGH002_1.py:4:1: PGH002 `warn` is deprecated in favor of `warning`
|
||||
PGH002_1.py:4:1: PGH002 [*] `warn` is deprecated in favor of `warning`
|
||||
|
|
||||
2 | from logging import warn
|
||||
3 |
|
||||
|
@ -11,7 +11,17 @@ PGH002_1.py:4:1: PGH002 `warn` is deprecated in favor of `warning`
|
|||
|
|
||||
= help: Replace with `warning`
|
||||
|
||||
PGH002_1.py:5:1: PGH002 `warn` is deprecated in favor of `warning`
|
||||
ℹ Safe fix
|
||||
1 1 | import logging
|
||||
2 2 | from logging import warn
|
||||
3 3 |
|
||||
4 |-logging.warn("this is not ok")
|
||||
4 |+logging.warning("this is not ok")
|
||||
5 5 | warn("not ok")
|
||||
6 6 |
|
||||
7 7 | logger = logging.getLogger(__name__)
|
||||
|
||||
PGH002_1.py:5:1: PGH002 [*] `warn` is deprecated in favor of `warning`
|
||||
|
|
||||
4 | logging.warn("this is not ok")
|
||||
5 | warn("not ok")
|
||||
|
@ -21,7 +31,17 @@ PGH002_1.py:5:1: PGH002 `warn` is deprecated in favor of `warning`
|
|||
|
|
||||
= help: Replace with `warning`
|
||||
|
||||
PGH002_1.py:8:1: PGH002 `warn` is deprecated in favor of `warning`
|
||||
ℹ Safe fix
|
||||
2 2 | from logging import warn
|
||||
3 3 |
|
||||
4 4 | logging.warn("this is not ok")
|
||||
5 |-warn("not ok")
|
||||
5 |+logging.warning("not ok")
|
||||
6 6 |
|
||||
7 7 | logger = logging.getLogger(__name__)
|
||||
8 8 | logger.warn("this is not ok")
|
||||
|
||||
PGH002_1.py:8:1: PGH002 [*] `warn` is deprecated in favor of `warning`
|
||||
|
|
||||
7 | logger = logging.getLogger(__name__)
|
||||
8 | logger.warn("this is not ok")
|
||||
|
@ -29,4 +49,11 @@ PGH002_1.py:8:1: PGH002 `warn` is deprecated in favor of `warning`
|
|||
|
|
||||
= help: Replace with `warning`
|
||||
|
||||
ℹ Safe fix
|
||||
5 5 | warn("not ok")
|
||||
6 6 |
|
||||
7 7 | logger = logging.getLogger(__name__)
|
||||
8 |-logger.warn("this is not ok")
|
||||
8 |+logger.warning("this is not ok")
|
||||
|
||||
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pygrep_hooks/mod.rs
|
||||
---
|
||||
PGH002_1.py:4:1: PGH002 [*] `warn` is deprecated in favor of `warning`
|
||||
|
|
||||
2 | from logging import warn
|
||||
3 |
|
||||
4 | logging.warn("this is not ok")
|
||||
| ^^^^^^^^^^^^ PGH002
|
||||
5 | warn("not ok")
|
||||
|
|
||||
= help: Replace with `warning`
|
||||
|
||||
ℹ Safe fix
|
||||
1 1 | import logging
|
||||
2 2 | from logging import warn
|
||||
3 3 |
|
||||
4 |-logging.warn("this is not ok")
|
||||
4 |+logging.warning("this is not ok")
|
||||
5 5 | warn("not ok")
|
||||
6 6 |
|
||||
7 7 | logger = logging.getLogger(__name__)
|
||||
|
||||
PGH002_1.py:5:1: PGH002 [*] `warn` is deprecated in favor of `warning`
|
||||
|
|
||||
4 | logging.warn("this is not ok")
|
||||
5 | warn("not ok")
|
||||
| ^^^^ PGH002
|
||||
6 |
|
||||
7 | logger = logging.getLogger(__name__)
|
||||
|
|
||||
= help: Replace with `warning`
|
||||
|
||||
ℹ Safe fix
|
||||
2 2 | from logging import warn
|
||||
3 3 |
|
||||
4 4 | logging.warn("this is not ok")
|
||||
5 |-warn("not ok")
|
||||
5 |+logging.warning("not ok")
|
||||
6 6 |
|
||||
7 7 | logger = logging.getLogger(__name__)
|
||||
8 8 | logger.warn("this is not ok")
|
||||
|
||||
PGH002_1.py:8:1: PGH002 [*] `warn` is deprecated in favor of `warning`
|
||||
|
|
||||
7 | logger = logging.getLogger(__name__)
|
||||
8 | logger.warn("this is not ok")
|
||||
| ^^^^^^^^^^^ PGH002
|
||||
|
|
||||
= help: Replace with `warning`
|
||||
|
||||
ℹ Safe fix
|
||||
5 5 | warn("not ok")
|
||||
6 6 |
|
||||
7 7 | logger = logging.getLogger(__name__)
|
||||
8 |-logger.warn("this is not ok")
|
||||
8 |+logger.warning("this is not ok")
|
||||
|
||||
|
|
@ -14,11 +14,11 @@ mod tests {
|
|||
|
||||
use crate::registry::Rule;
|
||||
use crate::rules::pylint;
|
||||
use crate::settings::types::PreviewMode;
|
||||
|
||||
use crate::assert_messages;
|
||||
use crate::settings::types::PythonVersion;
|
||||
use crate::settings::LinterSettings;
|
||||
use crate::test::test_path;
|
||||
use crate::{assert_messages, settings};
|
||||
|
||||
#[test_case(Rule::AndOrTernary, Path::new("and_or_ternary.py"))]
|
||||
#[test_case(Rule::AssertOnStringLiteral, Path::new("assert_on_string_literal.py"))]
|
||||
|
@ -194,25 +194,6 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::UselessElseOnLoop, Path::new("useless_else_on_loop.py"))]
|
||||
#[test_case(Rule::CollapsibleElseIf, Path::new("collapsible_else_if.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
"preview__{}_{}",
|
||||
rule_code.noqa_code(),
|
||||
path.to_string_lossy()
|
||||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("pylint").join(path).as_path(),
|
||||
&settings::LinterSettings {
|
||||
preview: PreviewMode::Enabled,
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_isinstance_calls() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
|
|
|
@ -84,13 +84,8 @@ pub(crate) fn collapsible_else_if(checker: &mut Checker, stmt: &Stmt) {
|
|||
CollapsibleElseIf,
|
||||
TextRange::new(else_clause.start(), first.start()),
|
||||
);
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
diagnostic.try_set_fix(|| {
|
||||
convert_to_elif(first, else_clause, checker.locator(), checker.stylist())
|
||||
});
|
||||
}
|
||||
|
||||
diagnostic
|
||||
.try_set_fix(|| convert_to_elif(first, else_clause, checker.locator(), checker.stylist()));
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,6 @@ pub(crate) fn useless_else_on_loop(
|
|||
let else_range = identifier::else_(stmt, checker.locator().contents()).expect("else clause");
|
||||
|
||||
let mut diagnostic = Diagnostic::new(UselessElseOnLoop, else_range);
|
||||
|
||||
if checker.settings.preview.is_enabled() {
|
||||
diagnostic.try_set_fix(|| {
|
||||
remove_else(
|
||||
stmt,
|
||||
|
@ -86,8 +84,6 @@ pub(crate) fn useless_else_on_loop(
|
|||
checker.stylist(),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pylint/mod.rs
|
||||
---
|
||||
collapsible_else_if.py:37:5: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
collapsible_else_if.py:37:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
35 | if 1:
|
||||
36 | pass
|
||||
|
@ -13,7 +13,20 @@ collapsible_else_if.py:37:5: PLR5501 Use `elif` instead of `else` then `if`, to
|
|||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
collapsible_else_if.py:45:5: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
ℹ Safe fix
|
||||
34 34 | def not_ok0():
|
||||
35 35 | if 1:
|
||||
36 36 | pass
|
||||
37 |- else:
|
||||
38 |- if 2:
|
||||
39 |- pass
|
||||
37 |+ elif 2:
|
||||
38 |+ pass
|
||||
40 39 |
|
||||
41 40 |
|
||||
42 41 | def not_ok1():
|
||||
|
||||
collapsible_else_if.py:45:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
43 | if 1:
|
||||
44 | pass
|
||||
|
@ -26,7 +39,23 @@ collapsible_else_if.py:45:5: PLR5501 Use `elif` instead of `else` then `if`, to
|
|||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
collapsible_else_if.py:55:5: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
ℹ Safe fix
|
||||
42 42 | def not_ok1():
|
||||
43 43 | if 1:
|
||||
44 44 | pass
|
||||
45 |+ elif 2:
|
||||
46 |+ pass
|
||||
45 47 | else:
|
||||
46 |- if 2:
|
||||
47 |- pass
|
||||
48 |- else:
|
||||
49 |- pass
|
||||
48 |+ pass
|
||||
50 49 |
|
||||
51 50 |
|
||||
52 51 | def not_ok1_with_comments():
|
||||
|
||||
collapsible_else_if.py:55:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
53 | if 1:
|
||||
54 | pass
|
||||
|
@ -40,7 +69,24 @@ collapsible_else_if.py:55:5: PLR5501 Use `elif` instead of `else` then `if`, to
|
|||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
collapsible_else_if.py:69:5: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
ℹ Safe fix
|
||||
52 52 | def not_ok1_with_comments():
|
||||
53 53 | if 1:
|
||||
54 54 | pass
|
||||
55 |+ elif 2:
|
||||
56 |+ pass
|
||||
55 57 | else:
|
||||
56 |- # inner comment
|
||||
57 |- if 2:
|
||||
58 |- pass
|
||||
59 |- else:
|
||||
60 |- pass # final pass comment
|
||||
58 |+ pass # final pass comment
|
||||
61 59 |
|
||||
62 60 |
|
||||
63 61 | # Regression test for https://github.com/apache/airflow/blob/f1e1cdcc3b2826e68ba133f350300b5065bbca33/airflow/models/dag.py#L1737
|
||||
|
||||
collapsible_else_if.py:69:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
67 | elif True:
|
||||
68 | print(2)
|
||||
|
@ -53,7 +99,23 @@ collapsible_else_if.py:69:5: PLR5501 Use `elif` instead of `else` then `if`, to
|
|||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
collapsible_else_if.py:79:5: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
ℹ Safe fix
|
||||
66 66 | print(1)
|
||||
67 67 | elif True:
|
||||
68 68 | print(2)
|
||||
69 |+ elif True:
|
||||
70 |+ print(3)
|
||||
69 71 | else:
|
||||
70 |- if True:
|
||||
71 |- print(3)
|
||||
72 |- else:
|
||||
73 |- print(4)
|
||||
72 |+ print(4)
|
||||
74 73 |
|
||||
75 74 |
|
||||
76 75 | def not_ok3():
|
||||
|
||||
collapsible_else_if.py:79:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
77 | if 1:
|
||||
78 | pass
|
||||
|
@ -65,7 +127,20 @@ collapsible_else_if.py:79:5: PLR5501 Use `elif` instead of `else` then `if`, to
|
|||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
collapsible_else_if.py:87:5: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
ℹ Safe fix
|
||||
76 76 | def not_ok3():
|
||||
77 77 | if 1:
|
||||
78 78 | pass
|
||||
79 |- else:
|
||||
80 |- if 2: pass
|
||||
81 |- else: pass
|
||||
79 |+ elif 2: pass
|
||||
80 |+ else: pass
|
||||
82 81 |
|
||||
83 82 |
|
||||
84 83 | def not_ok4():
|
||||
|
||||
collapsible_else_if.py:87:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
85 | if 1:
|
||||
86 | pass
|
||||
|
@ -78,7 +153,21 @@ collapsible_else_if.py:87:5: PLR5501 Use `elif` instead of `else` then `if`, to
|
|||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
collapsible_else_if.py:96:5: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
ℹ Safe fix
|
||||
84 84 | def not_ok4():
|
||||
85 85 | if 1:
|
||||
86 86 | pass
|
||||
87 |+ elif 2: pass
|
||||
87 88 | else:
|
||||
88 |- if 2: pass
|
||||
89 |- else:
|
||||
90 |- pass
|
||||
89 |+ pass
|
||||
91 90 |
|
||||
92 91 |
|
||||
93 92 | def not_ok5():
|
||||
|
||||
collapsible_else_if.py:96:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
94 | if 1:
|
||||
95 | pass
|
||||
|
@ -91,4 +180,16 @@ collapsible_else_if.py:96:5: PLR5501 Use `elif` instead of `else` then `if`, to
|
|||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
93 93 | def not_ok5():
|
||||
94 94 | if 1:
|
||||
95 95 | pass
|
||||
96 |- else:
|
||||
97 |- if 2:
|
||||
98 |- pass
|
||||
99 |- else: pass
|
||||
96 |+ elif 2:
|
||||
97 |+ pass
|
||||
98 |+ else: pass
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pylint/mod.rs
|
||||
---
|
||||
useless_else_on_loop.py:9:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
useless_else_on_loop.py:9:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
7 | if i % 2:
|
||||
8 | return i
|
||||
|
@ -12,7 +12,18 @@ useless_else_on_loop.py:9:5: PLW0120 `else` clause on loop without a `break` sta
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
useless_else_on_loop.py:18:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
ℹ Safe fix
|
||||
6 6 | for i in range(10):
|
||||
7 7 | if i % 2:
|
||||
8 8 | return i
|
||||
9 |- else: # [useless-else-on-loop]
|
||||
10 |- print("math is broken")
|
||||
9 |+ print("math is broken")
|
||||
11 10 | return None
|
||||
12 11 |
|
||||
13 12 |
|
||||
|
||||
useless_else_on_loop.py:18:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
16 | while True:
|
||||
17 | return 1
|
||||
|
@ -23,7 +34,18 @@ useless_else_on_loop.py:18:5: PLW0120 `else` clause on loop without a `break` st
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
useless_else_on_loop.py:30:1: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
ℹ Safe fix
|
||||
15 15 | """else + return is not acceptable."""
|
||||
16 16 | while True:
|
||||
17 17 | return 1
|
||||
18 |- else: # [useless-else-on-loop]
|
||||
19 |- print("math is broken")
|
||||
18 |+ print("math is broken")
|
||||
20 19 | return None
|
||||
21 20 |
|
||||
22 21 |
|
||||
|
||||
useless_else_on_loop.py:30:1: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
28 | break
|
||||
29 |
|
||||
|
@ -33,7 +55,18 @@ useless_else_on_loop.py:30:1: PLW0120 `else` clause on loop without a `break` st
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
useless_else_on_loop.py:37:1: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
ℹ Safe fix
|
||||
27 27 | for _ in range(10):
|
||||
28 28 | break
|
||||
29 29 |
|
||||
30 |-else: # [useless-else-on-loop]
|
||||
31 |- print("or else!")
|
||||
30 |+print("or else!")
|
||||
32 31 |
|
||||
33 32 |
|
||||
34 33 | while True:
|
||||
|
||||
useless_else_on_loop.py:37:1: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
35 | while False:
|
||||
36 | break
|
||||
|
@ -43,7 +76,18 @@ useless_else_on_loop.py:37:1: PLW0120 `else` clause on loop without a `break` st
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
useless_else_on_loop.py:42:1: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
ℹ Safe fix
|
||||
34 34 | while True:
|
||||
35 35 | while False:
|
||||
36 36 | break
|
||||
37 |-else: # [useless-else-on-loop]
|
||||
38 |- print("or else!")
|
||||
37 |+print("or else!")
|
||||
39 38 |
|
||||
40 39 | for j in range(10):
|
||||
41 40 | pass
|
||||
|
||||
useless_else_on_loop.py:42:1: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
40 | for j in range(10):
|
||||
41 | pass
|
||||
|
@ -54,7 +98,22 @@ useless_else_on_loop.py:42:1: PLW0120 `else` clause on loop without a `break` st
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
useless_else_on_loop.py:88:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
ℹ Safe fix
|
||||
39 39 |
|
||||
40 40 | for j in range(10):
|
||||
41 41 | pass
|
||||
42 |-else: # [useless-else-on-loop]
|
||||
43 |- print("fat chance")
|
||||
44 |- for j in range(10):
|
||||
45 |- break
|
||||
42 |+print("fat chance")
|
||||
43 |+for j in range(10):
|
||||
44 |+ break
|
||||
46 45 |
|
||||
47 46 |
|
||||
48 47 | def test_return_for2():
|
||||
|
||||
useless_else_on_loop.py:88:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
86 | else:
|
||||
87 | print("all right")
|
||||
|
@ -65,7 +124,18 @@ useless_else_on_loop.py:88:5: PLW0120 `else` clause on loop without a `break` st
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
useless_else_on_loop.py:98:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
ℹ Safe fix
|
||||
85 85 | break
|
||||
86 86 | else:
|
||||
87 87 | print("all right")
|
||||
88 |- else: # [useless-else-on-loop]
|
||||
89 |- return True
|
||||
88 |+ return True
|
||||
90 89 | return False
|
||||
91 90 |
|
||||
92 91 |
|
||||
|
||||
useless_else_on_loop.py:98:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
96 | for _ in range(3):
|
||||
97 | pass
|
||||
|
@ -76,7 +146,20 @@ useless_else_on_loop.py:98:9: PLW0120 `else` clause on loop without a `break` st
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
useless_else_on_loop.py:144:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
ℹ Safe fix
|
||||
95 95 | for _ in range(10):
|
||||
96 96 | for _ in range(3):
|
||||
97 97 | pass
|
||||
98 |- else:
|
||||
99 |- if 1 < 2: # pylint: disable=comparison-of-constants
|
||||
100 |- break
|
||||
98 |+ if 1 < 2: # pylint: disable=comparison-of-constants
|
||||
99 |+ break
|
||||
101 100 | else:
|
||||
102 101 | return True
|
||||
103 102 | return False
|
||||
|
||||
useless_else_on_loop.py:144:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
142 | for j in range(10):
|
||||
143 | pass
|
||||
|
@ -87,4 +170,18 @@ useless_else_on_loop.py:144:5: PLW0120 `else` clause on loop without a `break` s
|
|||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
141 141 | """Retain the comment within the `else` block"""
|
||||
142 142 | for j in range(10):
|
||||
143 143 | pass
|
||||
144 |- else:
|
||||
145 |- # [useless-else-on-loop]
|
||||
146 |- print("fat chance")
|
||||
147 |- for j in range(10):
|
||||
148 |- break
|
||||
144 |+ # [useless-else-on-loop]
|
||||
145 |+ print("fat chance")
|
||||
146 |+ for j in range(10):
|
||||
147 |+ break
|
||||
|
||||
|
||||
|
|
|
@ -1,195 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pylint/mod.rs
|
||||
---
|
||||
collapsible_else_if.py:37:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
35 | if 1:
|
||||
36 | pass
|
||||
37 | else:
|
||||
| _____^
|
||||
38 | | if 2:
|
||||
| |________^ PLR5501
|
||||
39 | pass
|
||||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
34 34 | def not_ok0():
|
||||
35 35 | if 1:
|
||||
36 36 | pass
|
||||
37 |- else:
|
||||
38 |- if 2:
|
||||
39 |- pass
|
||||
37 |+ elif 2:
|
||||
38 |+ pass
|
||||
40 39 |
|
||||
41 40 |
|
||||
42 41 | def not_ok1():
|
||||
|
||||
collapsible_else_if.py:45:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
43 | if 1:
|
||||
44 | pass
|
||||
45 | else:
|
||||
| _____^
|
||||
46 | | if 2:
|
||||
| |________^ PLR5501
|
||||
47 | pass
|
||||
48 | else:
|
||||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
42 42 | def not_ok1():
|
||||
43 43 | if 1:
|
||||
44 44 | pass
|
||||
45 |+ elif 2:
|
||||
46 |+ pass
|
||||
45 47 | else:
|
||||
46 |- if 2:
|
||||
47 |- pass
|
||||
48 |- else:
|
||||
49 |- pass
|
||||
48 |+ pass
|
||||
50 49 |
|
||||
51 50 |
|
||||
52 51 | def not_ok1_with_comments():
|
||||
|
||||
collapsible_else_if.py:55:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
53 | if 1:
|
||||
54 | pass
|
||||
55 | else:
|
||||
| _____^
|
||||
56 | | # inner comment
|
||||
57 | | if 2:
|
||||
| |________^ PLR5501
|
||||
58 | pass
|
||||
59 | else:
|
||||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
52 52 | def not_ok1_with_comments():
|
||||
53 53 | if 1:
|
||||
54 54 | pass
|
||||
55 |+ elif 2:
|
||||
56 |+ pass
|
||||
55 57 | else:
|
||||
56 |- # inner comment
|
||||
57 |- if 2:
|
||||
58 |- pass
|
||||
59 |- else:
|
||||
60 |- pass # final pass comment
|
||||
58 |+ pass # final pass comment
|
||||
61 59 |
|
||||
62 60 |
|
||||
63 61 | # Regression test for https://github.com/apache/airflow/blob/f1e1cdcc3b2826e68ba133f350300b5065bbca33/airflow/models/dag.py#L1737
|
||||
|
||||
collapsible_else_if.py:69:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
67 | elif True:
|
||||
68 | print(2)
|
||||
69 | else:
|
||||
| _____^
|
||||
70 | | if True:
|
||||
| |________^ PLR5501
|
||||
71 | print(3)
|
||||
72 | else:
|
||||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
66 66 | print(1)
|
||||
67 67 | elif True:
|
||||
68 68 | print(2)
|
||||
69 |+ elif True:
|
||||
70 |+ print(3)
|
||||
69 71 | else:
|
||||
70 |- if True:
|
||||
71 |- print(3)
|
||||
72 |- else:
|
||||
73 |- print(4)
|
||||
72 |+ print(4)
|
||||
74 73 |
|
||||
75 74 |
|
||||
76 75 | def not_ok3():
|
||||
|
||||
collapsible_else_if.py:79:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
77 | if 1:
|
||||
78 | pass
|
||||
79 | else:
|
||||
| _____^
|
||||
80 | | if 2: pass
|
||||
| |________^ PLR5501
|
||||
81 | else: pass
|
||||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
76 76 | def not_ok3():
|
||||
77 77 | if 1:
|
||||
78 78 | pass
|
||||
79 |- else:
|
||||
80 |- if 2: pass
|
||||
81 |- else: pass
|
||||
79 |+ elif 2: pass
|
||||
80 |+ else: pass
|
||||
82 81 |
|
||||
83 82 |
|
||||
84 83 | def not_ok4():
|
||||
|
||||
collapsible_else_if.py:87:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
85 | if 1:
|
||||
86 | pass
|
||||
87 | else:
|
||||
| _____^
|
||||
88 | | if 2: pass
|
||||
| |________^ PLR5501
|
||||
89 | else:
|
||||
90 | pass
|
||||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
84 84 | def not_ok4():
|
||||
85 85 | if 1:
|
||||
86 86 | pass
|
||||
87 |+ elif 2: pass
|
||||
87 88 | else:
|
||||
88 |- if 2: pass
|
||||
89 |- else:
|
||||
90 |- pass
|
||||
89 |+ pass
|
||||
91 90 |
|
||||
92 91 |
|
||||
93 92 | def not_ok5():
|
||||
|
||||
collapsible_else_if.py:96:5: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
|
||||
|
|
||||
94 | if 1:
|
||||
95 | pass
|
||||
96 | else:
|
||||
| _____^
|
||||
97 | | if 2:
|
||||
| |________^ PLR5501
|
||||
98 | pass
|
||||
99 | else: pass
|
||||
|
|
||||
= help: Convert to `elif`
|
||||
|
||||
ℹ Safe fix
|
||||
93 93 | def not_ok5():
|
||||
94 94 | if 1:
|
||||
95 95 | pass
|
||||
96 |- else:
|
||||
97 |- if 2:
|
||||
98 |- pass
|
||||
99 |- else: pass
|
||||
96 |+ elif 2:
|
||||
97 |+ pass
|
||||
98 |+ else: pass
|
||||
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pylint/mod.rs
|
||||
---
|
||||
useless_else_on_loop.py:9:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
7 | if i % 2:
|
||||
8 | return i
|
||||
9 | else: # [useless-else-on-loop]
|
||||
| ^^^^ PLW0120
|
||||
10 | print("math is broken")
|
||||
11 | return None
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
6 6 | for i in range(10):
|
||||
7 7 | if i % 2:
|
||||
8 8 | return i
|
||||
9 |- else: # [useless-else-on-loop]
|
||||
10 |- print("math is broken")
|
||||
9 |+ print("math is broken")
|
||||
11 10 | return None
|
||||
12 11 |
|
||||
13 12 |
|
||||
|
||||
useless_else_on_loop.py:18:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
16 | while True:
|
||||
17 | return 1
|
||||
18 | else: # [useless-else-on-loop]
|
||||
| ^^^^ PLW0120
|
||||
19 | print("math is broken")
|
||||
20 | return None
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
15 15 | """else + return is not acceptable."""
|
||||
16 16 | while True:
|
||||
17 17 | return 1
|
||||
18 |- else: # [useless-else-on-loop]
|
||||
19 |- print("math is broken")
|
||||
18 |+ print("math is broken")
|
||||
20 19 | return None
|
||||
21 20 |
|
||||
22 21 |
|
||||
|
||||
useless_else_on_loop.py:30:1: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
28 | break
|
||||
29 |
|
||||
30 | else: # [useless-else-on-loop]
|
||||
| ^^^^ PLW0120
|
||||
31 | print("or else!")
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
27 27 | for _ in range(10):
|
||||
28 28 | break
|
||||
29 29 |
|
||||
30 |-else: # [useless-else-on-loop]
|
||||
31 |- print("or else!")
|
||||
30 |+print("or else!")
|
||||
32 31 |
|
||||
33 32 |
|
||||
34 33 | while True:
|
||||
|
||||
useless_else_on_loop.py:37:1: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
35 | while False:
|
||||
36 | break
|
||||
37 | else: # [useless-else-on-loop]
|
||||
| ^^^^ PLW0120
|
||||
38 | print("or else!")
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
34 34 | while True:
|
||||
35 35 | while False:
|
||||
36 36 | break
|
||||
37 |-else: # [useless-else-on-loop]
|
||||
38 |- print("or else!")
|
||||
37 |+print("or else!")
|
||||
39 38 |
|
||||
40 39 | for j in range(10):
|
||||
41 40 | pass
|
||||
|
||||
useless_else_on_loop.py:42:1: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
40 | for j in range(10):
|
||||
41 | pass
|
||||
42 | else: # [useless-else-on-loop]
|
||||
| ^^^^ PLW0120
|
||||
43 | print("fat chance")
|
||||
44 | for j in range(10):
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
39 39 |
|
||||
40 40 | for j in range(10):
|
||||
41 41 | pass
|
||||
42 |-else: # [useless-else-on-loop]
|
||||
43 |- print("fat chance")
|
||||
44 |- for j in range(10):
|
||||
45 |- break
|
||||
42 |+print("fat chance")
|
||||
43 |+for j in range(10):
|
||||
44 |+ break
|
||||
46 45 |
|
||||
47 46 |
|
||||
48 47 | def test_return_for2():
|
||||
|
||||
useless_else_on_loop.py:88:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
86 | else:
|
||||
87 | print("all right")
|
||||
88 | else: # [useless-else-on-loop]
|
||||
| ^^^^ PLW0120
|
||||
89 | return True
|
||||
90 | return False
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
85 85 | break
|
||||
86 86 | else:
|
||||
87 87 | print("all right")
|
||||
88 |- else: # [useless-else-on-loop]
|
||||
89 |- return True
|
||||
88 |+ return True
|
||||
90 89 | return False
|
||||
91 90 |
|
||||
92 91 |
|
||||
|
||||
useless_else_on_loop.py:98:9: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
96 | for _ in range(3):
|
||||
97 | pass
|
||||
98 | else:
|
||||
| ^^^^ PLW0120
|
||||
99 | if 1 < 2: # pylint: disable=comparison-of-constants
|
||||
100 | break
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
95 95 | for _ in range(10):
|
||||
96 96 | for _ in range(3):
|
||||
97 97 | pass
|
||||
98 |- else:
|
||||
99 |- if 1 < 2: # pylint: disable=comparison-of-constants
|
||||
100 |- break
|
||||
98 |+ if 1 < 2: # pylint: disable=comparison-of-constants
|
||||
99 |+ break
|
||||
101 100 | else:
|
||||
102 101 | return True
|
||||
103 102 | return False
|
||||
|
||||
useless_else_on_loop.py:144:5: PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
|
||||
|
|
||||
142 | for j in range(10):
|
||||
143 | pass
|
||||
144 | else:
|
||||
| ^^^^ PLW0120
|
||||
145 | # [useless-else-on-loop]
|
||||
146 | print("fat chance")
|
||||
|
|
||||
= help: Remove `else`
|
||||
|
||||
ℹ Safe fix
|
||||
141 141 | """Retain the comment within the `else` block"""
|
||||
142 142 | for j in range(10):
|
||||
143 143 | pass
|
||||
144 |- else:
|
||||
145 |- # [useless-else-on-loop]
|
||||
146 |- print("fat chance")
|
||||
147 |- for j in range(10):
|
||||
148 |- break
|
||||
144 |+ # [useless-else-on-loop]
|
||||
145 |+ print("fat chance")
|
||||
146 |+ for j in range(10):
|
||||
147 |+ break
|
||||
|
||||
|
|
@ -98,14 +98,10 @@ pub(crate) fn use_pep585_annotation(
|
|||
if checker.semantic().is_builtin(name) {
|
||||
diagnostic.set_fix(Fix::applicable_edit(
|
||||
Edit::range_replacement((*name).to_string(), expr.range()),
|
||||
if checker.settings.preview.is_enabled() {
|
||||
if checker.settings.target_version >= PythonVersion::Py310 {
|
||||
Applicability::Safe
|
||||
} else {
|
||||
Applicability::Unsafe
|
||||
}
|
||||
} else {
|
||||
Applicability::Safe
|
||||
},
|
||||
));
|
||||
}
|
||||
|
@ -122,14 +118,10 @@ pub(crate) fn use_pep585_annotation(
|
|||
Ok(Fix::applicable_edits(
|
||||
import_edit,
|
||||
[reference_edit],
|
||||
if checker.settings.preview.is_enabled() {
|
||||
if checker.settings.target_version >= PythonVersion::Py310 {
|
||||
Applicability::Safe
|
||||
} else {
|
||||
Applicability::Unsafe
|
||||
}
|
||||
} else {
|
||||
Applicability::Unsafe
|
||||
},
|
||||
))
|
||||
});
|
||||
|
|
|
@ -78,14 +78,10 @@ pub(crate) fn use_pep604_annotation(
|
|||
&& !checker.semantic().in_complex_string_type_definition()
|
||||
&& is_allowed_value(slice);
|
||||
|
||||
let applicability = if checker.settings.preview.is_enabled() {
|
||||
if checker.settings.target_version >= PythonVersion::Py310 {
|
||||
let applicability = if checker.settings.target_version >= PythonVersion::Py310 {
|
||||
Applicability::Safe
|
||||
} else {
|
||||
Applicability::Unsafe
|
||||
}
|
||||
} else {
|
||||
Applicability::Unsafe
|
||||
};
|
||||
|
||||
match operator {
|
||||
|
|
|
@ -239,7 +239,7 @@ UP006_0.py:61:10: UP006 [*] Use `collections.deque` instead of `typing.Deque` fo
|
|||
|
|
||||
= help: Replace with `collections.deque`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
20 20 |
|
||||
21 21 |
|
||||
22 22 | from typing import List as IList
|
||||
|
@ -265,7 +265,7 @@ UP006_0.py:65:10: UP006 [*] Use `collections.defaultdict` instead of `typing.Def
|
|||
|
|
||||
= help: Replace with `collections.defaultdict`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
20 20 |
|
||||
21 21 |
|
||||
22 22 | from typing import List as IList
|
||||
|
|
|
@ -9,7 +9,7 @@ UP006_1.py:9:10: UP006 [*] Use `collections.defaultdict` instead of `typing.Defa
|
|||
|
|
||||
= help: Replace with `collections.defaultdict`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
6 6 | from collections import defaultdict
|
||||
7 7 |
|
||||
8 8 |
|
||||
|
|
|
@ -9,7 +9,7 @@ UP006_3.py:7:11: UP006 [*] Use `collections.defaultdict` instead of `typing.Defa
|
|||
|
|
||||
= help: Replace with `collections.defaultdict`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
4 4 | from collections import defaultdict
|
||||
5 5 |
|
||||
6 6 |
|
||||
|
|
|
@ -9,7 +9,7 @@ UP007.py:6:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
3 3 | from typing import Union
|
||||
4 4 |
|
||||
5 5 |
|
||||
|
@ -27,7 +27,7 @@ UP007.py:10:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
7 7 | ...
|
||||
8 8 |
|
||||
9 9 |
|
||||
|
@ -45,7 +45,7 @@ UP007.py:14:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
11 11 | ...
|
||||
12 12 |
|
||||
13 13 |
|
||||
|
@ -63,7 +63,7 @@ UP007.py:14:26: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
11 11 | ...
|
||||
12 12 |
|
||||
13 13 |
|
||||
|
@ -81,7 +81,7 @@ UP007.py:18:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
15 15 | ...
|
||||
16 16 |
|
||||
17 17 |
|
||||
|
@ -99,7 +99,7 @@ UP007.py:22:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
19 19 | ...
|
||||
20 20 |
|
||||
21 21 |
|
||||
|
@ -117,7 +117,7 @@ UP007.py:26:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
23 23 | ...
|
||||
24 24 |
|
||||
25 25 |
|
||||
|
@ -135,7 +135,7 @@ UP007.py:30:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
27 27 | ...
|
||||
28 28 |
|
||||
29 29 |
|
||||
|
@ -153,7 +153,7 @@ UP007.py:34:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
31 31 | ...
|
||||
32 32 |
|
||||
33 33 |
|
||||
|
@ -171,7 +171,7 @@ UP007.py:38:11: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
35 35 | ...
|
||||
36 36 |
|
||||
37 37 |
|
||||
|
@ -189,7 +189,7 @@ UP007.py:38:27: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
35 35 | ...
|
||||
36 36 |
|
||||
37 37 |
|
||||
|
@ -207,7 +207,7 @@ UP007.py:42:11: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
39 39 | ...
|
||||
40 40 |
|
||||
41 41 |
|
||||
|
@ -226,7 +226,7 @@ UP007.py:55:8: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
52 52 |
|
||||
53 53 |
|
||||
54 54 | def f() -> None:
|
||||
|
@ -268,7 +268,7 @@ UP007.py:60:8: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
57 57 |
|
||||
58 58 | x = Union[str, int]
|
||||
59 59 | x = Union["str", "int"]
|
||||
|
@ -287,7 +287,7 @@ UP007.py:61:8: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
58 58 | x = Union[str, int]
|
||||
59 59 | x = Union["str", "int"]
|
||||
60 60 | x: Union[str, int]
|
||||
|
@ -382,7 +382,7 @@ UP007.py:102:28: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
99 99 |
|
||||
100 100 | # Regression test for: https://github.com/astral-sh/ruff/issues/7131
|
||||
101 101 | class ServiceRefOrValue:
|
||||
|
@ -404,7 +404,7 @@ UP007.py:110:28: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
107 107 |
|
||||
108 108 | # Regression test for: https://github.com/astral-sh/ruff/issues/7201
|
||||
109 109 | class ServiceRefOrValue:
|
||||
|
@ -423,7 +423,7 @@ UP007.py:120:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
117 117 |
|
||||
118 118 |
|
||||
119 119 | # Regression test for: https://github.com/astral-sh/ruff/issues/8609
|
||||
|
|
|
@ -10,7 +10,7 @@ future_annotations.py:34:18: UP006 [*] Use `list` instead of `List` for type ann
|
|||
|
|
||||
= help: Replace with `list`
|
||||
|
||||
ℹ Safe fix
|
||||
ℹ Unsafe fix
|
||||
31 31 | return cls(x=0, y=0)
|
||||
32 32 |
|
||||
33 33 |
|
||||
|
|
|
@ -10,7 +10,7 @@ future_annotations.py:40:4: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
37 37 | return y
|
||||
38 38 |
|
||||
39 39 |
|
||||
|
@ -28,7 +28,7 @@ future_annotations.py:42:21: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
39 39 |
|
||||
40 40 | x: Optional[int] = None
|
||||
41 41 |
|
||||
|
|
|
@ -11,8 +11,7 @@ mod tests {
|
|||
use test_case::test_case;
|
||||
|
||||
use crate::registry::Rule;
|
||||
use crate::settings::types::PreviewMode;
|
||||
use crate::settings::LinterSettings;
|
||||
|
||||
use crate::test::test_path;
|
||||
use crate::{assert_messages, settings};
|
||||
|
||||
|
@ -35,22 +34,4 @@ mod tests {
|
|||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::ErrorInsteadOfException, Path::new("TRY400.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
"preview__{}_{}",
|
||||
rule_code.noqa_code(),
|
||||
path.to_string_lossy()
|
||||
);
|
||||
let diagnostics = test_path(
|
||||
Path::new("tryceratops").join(path).as_path(),
|
||||
&LinterSettings {
|
||||
preview: PreviewMode::Enabled,
|
||||
..LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ pub(crate) fn error_instead_of_exception(checker: &mut Checker, handlers: &[Exce
|
|||
if matches!(logging_level, LoggingLevel::Error) {
|
||||
if exc_info(&expr.arguments, checker.semantic()).is_none() {
|
||||
let mut diagnostic = Diagnostic::new(ErrorInsteadOfException, expr.range());
|
||||
if checker.settings.preview.is_enabled() {
|
||||
|
||||
match expr.func.as_ref() {
|
||||
Expr::Attribute(ast::ExprAttribute { attr, .. }) => {
|
||||
diagnostic.set_fix(Fix::applicable_edit(
|
||||
|
@ -109,8 +109,7 @@ pub(crate) fn error_instead_of_exception(checker: &mut Checker, handlers: &[Exce
|
|||
expr.start(),
|
||||
checker.semantic(),
|
||||
)?;
|
||||
let name_edit =
|
||||
Edit::range_replacement(binding, expr.func.range());
|
||||
let name_edit = Edit::range_replacement(binding, expr.func.range());
|
||||
Ok(Fix::applicable_edits(
|
||||
import_edit,
|
||||
[name_edit],
|
||||
|
@ -132,7 +131,7 @@ pub(crate) fn error_instead_of_exception(checker: &mut Checker, handlers: &[Exce
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/tryceratops/mod.rs
|
||||
---
|
||||
TRY400.py:16:9: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
TRY400.py:16:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
14 | a = 1
|
||||
15 | except Exception:
|
||||
|
@ -12,7 +12,17 @@ TRY400.py:16:9: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:19:13: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Safe fix
|
||||
13 13 | try:
|
||||
14 14 | a = 1
|
||||
15 15 | except Exception:
|
||||
16 |- logging.error("Context message here")
|
||||
16 |+ logging.exception("Context message here")
|
||||
17 17 |
|
||||
18 18 | if True:
|
||||
19 19 | logging.error("Context message here")
|
||||
|
||||
TRY400.py:19:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
18 | if True:
|
||||
19 | logging.error("Context message here")
|
||||
|
@ -20,7 +30,17 @@ TRY400.py:19:13: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:26:9: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Safe fix
|
||||
16 16 | logging.error("Context message here")
|
||||
17 17 |
|
||||
18 18 | if True:
|
||||
19 |- logging.error("Context message here")
|
||||
19 |+ logging.exception("Context message here")
|
||||
20 20 |
|
||||
21 21 |
|
||||
22 22 | def bad():
|
||||
|
||||
TRY400.py:26:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
24 | a = 1
|
||||
25 | except Exception:
|
||||
|
@ -31,7 +51,17 @@ TRY400.py:26:9: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:29:13: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Unsafe fix
|
||||
23 23 | try:
|
||||
24 24 | a = 1
|
||||
25 25 | except Exception:
|
||||
26 |- logger.error("Context message here")
|
||||
26 |+ logger.exception("Context message here")
|
||||
27 27 |
|
||||
28 28 | if True:
|
||||
29 29 | logger.error("Context message here")
|
||||
|
||||
TRY400.py:29:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
28 | if True:
|
||||
29 | logger.error("Context message here")
|
||||
|
@ -39,7 +69,17 @@ TRY400.py:29:13: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:36:9: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Unsafe fix
|
||||
26 26 | logger.error("Context message here")
|
||||
27 27 |
|
||||
28 28 | if True:
|
||||
29 |- logger.error("Context message here")
|
||||
29 |+ logger.exception("Context message here")
|
||||
30 30 |
|
||||
31 31 |
|
||||
32 32 | def bad():
|
||||
|
||||
TRY400.py:36:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
34 | a = 1
|
||||
35 | except Exception:
|
||||
|
@ -50,7 +90,17 @@ TRY400.py:36:9: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:39:13: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Unsafe fix
|
||||
33 33 | try:
|
||||
34 34 | a = 1
|
||||
35 35 | except Exception:
|
||||
36 |- log.error("Context message here")
|
||||
36 |+ log.exception("Context message here")
|
||||
37 37 |
|
||||
38 38 | if True:
|
||||
39 39 | log.error("Context message here")
|
||||
|
||||
TRY400.py:39:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
38 | if True:
|
||||
39 | log.error("Context message here")
|
||||
|
@ -58,7 +108,17 @@ TRY400.py:39:13: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:46:9: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Unsafe fix
|
||||
36 36 | log.error("Context message here")
|
||||
37 37 |
|
||||
38 38 | if True:
|
||||
39 |- log.error("Context message here")
|
||||
39 |+ log.exception("Context message here")
|
||||
40 40 |
|
||||
41 41 |
|
||||
42 42 | def bad():
|
||||
|
||||
TRY400.py:46:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
44 | a = 1
|
||||
45 | except Exception:
|
||||
|
@ -69,7 +129,17 @@ TRY400.py:46:9: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:49:13: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Unsafe fix
|
||||
43 43 | try:
|
||||
44 44 | a = 1
|
||||
45 45 | except Exception:
|
||||
46 |- self.logger.error("Context message here")
|
||||
46 |+ self.logger.exception("Context message here")
|
||||
47 47 |
|
||||
48 48 | if True:
|
||||
49 49 | self.logger.error("Context message here")
|
||||
|
||||
TRY400.py:49:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
48 | if True:
|
||||
49 | self.logger.error("Context message here")
|
||||
|
@ -77,7 +147,17 @@ TRY400.py:49:13: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:87:9: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Unsafe fix
|
||||
46 46 | self.logger.error("Context message here")
|
||||
47 47 |
|
||||
48 48 | if True:
|
||||
49 |- self.logger.error("Context message here")
|
||||
49 |+ self.logger.exception("Context message here")
|
||||
50 50 |
|
||||
51 51 |
|
||||
52 52 | def good():
|
||||
|
||||
TRY400.py:87:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
85 | a = 1
|
||||
86 | except Exception:
|
||||
|
@ -88,7 +168,17 @@ TRY400.py:87:9: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:90:13: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Safe fix
|
||||
84 84 | try:
|
||||
85 85 | a = 1
|
||||
86 86 | except Exception:
|
||||
87 |- error("Context message here")
|
||||
87 |+ exception("Context message here")
|
||||
88 88 |
|
||||
89 89 | if True:
|
||||
90 90 | error("Context message here")
|
||||
|
||||
TRY400.py:90:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
89 | if True:
|
||||
90 | error("Context message here")
|
||||
|
@ -96,7 +186,17 @@ TRY400.py:90:13: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
TRY400.py:121:13: TRY400 Use `logging.exception` instead of `logging.error`
|
||||
ℹ Safe fix
|
||||
87 87 | error("Context message here")
|
||||
88 88 |
|
||||
89 89 | if True:
|
||||
90 |- error("Context message here")
|
||||
90 |+ exception("Context message here")
|
||||
91 91 |
|
||||
92 92 |
|
||||
93 93 | def good():
|
||||
|
||||
TRY400.py:121:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
119 | b = 2
|
||||
120 | except Exception:
|
||||
|
@ -105,4 +205,11 @@ TRY400.py:121:13: TRY400 Use `logging.exception` instead of `logging.error`
|
|||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Safe fix
|
||||
118 118 | try:
|
||||
119 119 | b = 2
|
||||
120 120 | except Exception:
|
||||
121 |- error("Context message here")
|
||||
121 |+ exception("Context message here")
|
||||
|
||||
|
||||
|
|
|
@ -1,215 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/tryceratops/mod.rs
|
||||
---
|
||||
TRY400.py:16:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
14 | a = 1
|
||||
15 | except Exception:
|
||||
16 | logging.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
17 |
|
||||
18 | if True:
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Safe fix
|
||||
13 13 | try:
|
||||
14 14 | a = 1
|
||||
15 15 | except Exception:
|
||||
16 |- logging.error("Context message here")
|
||||
16 |+ logging.exception("Context message here")
|
||||
17 17 |
|
||||
18 18 | if True:
|
||||
19 19 | logging.error("Context message here")
|
||||
|
||||
TRY400.py:19:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
18 | if True:
|
||||
19 | logging.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Safe fix
|
||||
16 16 | logging.error("Context message here")
|
||||
17 17 |
|
||||
18 18 | if True:
|
||||
19 |- logging.error("Context message here")
|
||||
19 |+ logging.exception("Context message here")
|
||||
20 20 |
|
||||
21 21 |
|
||||
22 22 | def bad():
|
||||
|
||||
TRY400.py:26:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
24 | a = 1
|
||||
25 | except Exception:
|
||||
26 | logger.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
27 |
|
||||
28 | if True:
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Unsafe fix
|
||||
23 23 | try:
|
||||
24 24 | a = 1
|
||||
25 25 | except Exception:
|
||||
26 |- logger.error("Context message here")
|
||||
26 |+ logger.exception("Context message here")
|
||||
27 27 |
|
||||
28 28 | if True:
|
||||
29 29 | logger.error("Context message here")
|
||||
|
||||
TRY400.py:29:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
28 | if True:
|
||||
29 | logger.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Unsafe fix
|
||||
26 26 | logger.error("Context message here")
|
||||
27 27 |
|
||||
28 28 | if True:
|
||||
29 |- logger.error("Context message here")
|
||||
29 |+ logger.exception("Context message here")
|
||||
30 30 |
|
||||
31 31 |
|
||||
32 32 | def bad():
|
||||
|
||||
TRY400.py:36:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
34 | a = 1
|
||||
35 | except Exception:
|
||||
36 | log.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
37 |
|
||||
38 | if True:
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Unsafe fix
|
||||
33 33 | try:
|
||||
34 34 | a = 1
|
||||
35 35 | except Exception:
|
||||
36 |- log.error("Context message here")
|
||||
36 |+ log.exception("Context message here")
|
||||
37 37 |
|
||||
38 38 | if True:
|
||||
39 39 | log.error("Context message here")
|
||||
|
||||
TRY400.py:39:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
38 | if True:
|
||||
39 | log.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Unsafe fix
|
||||
36 36 | log.error("Context message here")
|
||||
37 37 |
|
||||
38 38 | if True:
|
||||
39 |- log.error("Context message here")
|
||||
39 |+ log.exception("Context message here")
|
||||
40 40 |
|
||||
41 41 |
|
||||
42 42 | def bad():
|
||||
|
||||
TRY400.py:46:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
44 | a = 1
|
||||
45 | except Exception:
|
||||
46 | self.logger.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
47 |
|
||||
48 | if True:
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Unsafe fix
|
||||
43 43 | try:
|
||||
44 44 | a = 1
|
||||
45 45 | except Exception:
|
||||
46 |- self.logger.error("Context message here")
|
||||
46 |+ self.logger.exception("Context message here")
|
||||
47 47 |
|
||||
48 48 | if True:
|
||||
49 49 | self.logger.error("Context message here")
|
||||
|
||||
TRY400.py:49:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
48 | if True:
|
||||
49 | self.logger.error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Unsafe fix
|
||||
46 46 | self.logger.error("Context message here")
|
||||
47 47 |
|
||||
48 48 | if True:
|
||||
49 |- self.logger.error("Context message here")
|
||||
49 |+ self.logger.exception("Context message here")
|
||||
50 50 |
|
||||
51 51 |
|
||||
52 52 | def good():
|
||||
|
||||
TRY400.py:87:9: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
85 | a = 1
|
||||
86 | except Exception:
|
||||
87 | error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
88 |
|
||||
89 | if True:
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Safe fix
|
||||
84 84 | try:
|
||||
85 85 | a = 1
|
||||
86 86 | except Exception:
|
||||
87 |- error("Context message here")
|
||||
87 |+ exception("Context message here")
|
||||
88 88 |
|
||||
89 89 | if True:
|
||||
90 90 | error("Context message here")
|
||||
|
||||
TRY400.py:90:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
89 | if True:
|
||||
90 | error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Safe fix
|
||||
87 87 | error("Context message here")
|
||||
88 88 |
|
||||
89 89 | if True:
|
||||
90 |- error("Context message here")
|
||||
90 |+ exception("Context message here")
|
||||
91 91 |
|
||||
92 92 |
|
||||
93 93 | def good():
|
||||
|
||||
TRY400.py:121:13: TRY400 [*] Use `logging.exception` instead of `logging.error`
|
||||
|
|
||||
119 | b = 2
|
||||
120 | except Exception:
|
||||
121 | error("Context message here")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
||||
|
|
||||
= help: Replace with `exception`
|
||||
|
||||
ℹ Safe fix
|
||||
118 118 | try:
|
||||
119 119 | b = 2
|
||||
120 120 | except Exception:
|
||||
121 |- error("Context message here")
|
||||
121 |+ exception("Context message here")
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue