mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
parent
95448ba669
commit
653a0ebf2d
18 changed files with 56 additions and 70 deletions
|
@ -46,8 +46,7 @@ where
|
|||
let mut diagnostic = Diagnostic::new(DeprecatedCElementTree, node.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let contents = checker.locator.slice(node.range());
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
contents.replacen("cElementTree", "ElementTree", 1),
|
||||
node.range(),
|
||||
)));
|
||||
|
|
|
@ -563,8 +563,7 @@ pub(crate) fn deprecated_import(
|
|||
);
|
||||
if checker.patch(Rule::DeprecatedImport) {
|
||||
if let Some(content) = fix {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
content,
|
||||
stmt.range(),
|
||||
)));
|
||||
|
|
|
@ -260,8 +260,7 @@ pub(crate) fn deprecated_mock_attribute(checker: &mut Checker, expr: &Expr) {
|
|||
value.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
"mock".to_string(),
|
||||
value.range(),
|
||||
)));
|
||||
|
@ -307,8 +306,7 @@ pub(crate) fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) {
|
|||
name.range(),
|
||||
);
|
||||
if let Some(content) = content.as_ref() {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
content.clone(),
|
||||
stmt.range(),
|
||||
)));
|
||||
|
|
|
@ -157,8 +157,7 @@ pub(crate) fn extraneous_parentheses(
|
|||
if settings.rules.should_fix(Rule::ExtraneousParentheses) {
|
||||
let contents =
|
||||
locator.slice(TextRange::new(start_range.start(), end_range.end()));
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
|
||||
diagnostic.set_fix(Fix::automatic(Edit::replacement(
|
||||
contents[1..contents.len() - 1].to_string(),
|
||||
start_range.start(),
|
||||
end_range.end(),
|
||||
|
|
|
@ -97,8 +97,7 @@ pub(crate) fn lru_cache_with_maxsize_none(checker: &mut Checker, decorator_list:
|
|||
)?;
|
||||
let reference_edit =
|
||||
Edit::range_replacement(binding, decorator.expression.range());
|
||||
#[allow(deprecated)]
|
||||
Ok(Fix::unspecified_edits(import_edit, [reference_edit]))
|
||||
Ok(Fix::automatic_edits(import_edit, [reference_edit]))
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -81,8 +81,7 @@ pub(crate) fn lru_cache_without_parameters(checker: &mut Checker, decorator_list
|
|||
TextRange::new(func.end(), decorator.end()),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
checker.generator().expr(func),
|
||||
decorator.expression.range(),
|
||||
)));
|
||||
|
|
|
@ -100,8 +100,7 @@ pub(crate) fn native_literals(
|
|||
Constant::Str(String::new())
|
||||
};
|
||||
let content = checker.generator().constant(&constant);
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -153,8 +152,7 @@ pub(crate) fn native_literals(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
arg_code.to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -468,8 +468,7 @@ pub(crate) fn printf_string_formatting(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(PrintfStringFormatting, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
contents,
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -65,8 +65,7 @@ fn generate_fix(
|
|||
} else {
|
||||
(stderr, stdout)
|
||||
};
|
||||
#[allow(deprecated)]
|
||||
Ok(Fix::unspecified_edits(
|
||||
Ok(Fix::suggested_edits(
|
||||
Edit::range_replacement("capture_output=True".to_string(), first.range()),
|
||||
[remove_argument(
|
||||
locator,
|
||||
|
|
|
@ -88,8 +88,7 @@ pub(crate) fn use_pep604_annotation(
|
|||
Pep604Operator::Optional => {
|
||||
let mut diagnostic = Diagnostic::new(NonPEP604Annotation, expr.range());
|
||||
if fixable && checker.patch(diagnostic.kind.rule()) {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::manual(Edit::range_replacement(
|
||||
checker.generator().expr(&optional(slice)),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -104,16 +103,14 @@ pub(crate) fn use_pep604_annotation(
|
|||
// Invalid type annotation.
|
||||
}
|
||||
Expr::Tuple(ast::ExprTuple { elts, .. }) => {
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::manual(Edit::range_replacement(
|
||||
checker.generator().expr(&union(elts)),
|
||||
expr.range(),
|
||||
)));
|
||||
}
|
||||
_ => {
|
||||
// Single argument.
|
||||
#[allow(deprecated)]
|
||||
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::manual(Edit::range_replacement(
|
||||
checker.generator().expr(slice),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -9,7 +9,7 @@ UP007.py:6:10: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible 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`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible 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`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible 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`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible 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`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible 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`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible 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`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
23 23 | ...
|
||||
24 24 |
|
||||
25 25 |
|
||||
|
@ -135,7 +135,7 @@ UP007.py:30:11: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
27 27 | ...
|
||||
28 28 |
|
||||
29 29 |
|
||||
|
@ -153,7 +153,7 @@ UP007.py:30:27: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
27 27 | ...
|
||||
28 28 |
|
||||
29 29 |
|
||||
|
@ -171,7 +171,7 @@ UP007.py:34:11: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
31 31 | ...
|
||||
32 32 |
|
||||
33 33 |
|
||||
|
@ -190,7 +190,7 @@ UP007.py:47:8: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
44 44 |
|
||||
45 45 |
|
||||
46 46 | def f() -> None:
|
||||
|
@ -232,7 +232,7 @@ UP007.py:52:8: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
49 49 |
|
||||
50 50 | x = Union[str, int]
|
||||
51 51 | x = Union["str", "int"]
|
||||
|
|
|
@ -10,7 +10,7 @@ UP011.py:5:21: UP011 [*] Unnecessary parentheses to `functools.lru_cache`
|
|||
|
|
||||
= help: Remove unnecessary parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
2 2 | from functools import lru_cache
|
||||
3 3 |
|
||||
4 4 |
|
||||
|
@ -29,7 +29,7 @@ UP011.py:10:11: UP011 [*] Unnecessary parentheses to `functools.lru_cache`
|
|||
|
|
||||
= help: Remove unnecessary parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
7 7 | pass
|
||||
8 8 |
|
||||
9 9 |
|
||||
|
@ -49,7 +49,7 @@ UP011.py:16:21: UP011 [*] Unnecessary parentheses to `functools.lru_cache`
|
|||
|
|
||||
= help: Remove unnecessary parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
13 13 |
|
||||
14 14 |
|
||||
15 15 | @other_decorator
|
||||
|
@ -68,7 +68,7 @@ UP011.py:21:21: UP011 [*] Unnecessary parentheses to `functools.lru_cache`
|
|||
|
|
||||
= help: Remove unnecessary parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
18 18 | pass
|
||||
19 19 |
|
||||
20 20 |
|
||||
|
|
|
@ -11,7 +11,7 @@ UP018.py:21:1: UP018 [*] Unnecessary call to `str`
|
|||
|
|
||||
= help: Replace with empty string
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
18 18 | f"{f'{str()}'}"
|
||||
19 19 |
|
||||
20 20 | # These become string or byte literals
|
||||
|
@ -32,7 +32,7 @@ UP018.py:22:1: UP018 [*] Unnecessary call to `str`
|
|||
|
|
||||
= help: Replace with empty string
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
19 19 |
|
||||
20 20 | # These become string or byte literals
|
||||
21 21 | str()
|
||||
|
@ -54,7 +54,7 @@ UP018.py:23:1: UP018 [*] Unnecessary call to `str`
|
|||
|
|
||||
= help: Replace with empty string
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
20 20 | # These become string or byte literals
|
||||
21 21 | str()
|
||||
22 22 | str("foo")
|
||||
|
@ -77,7 +77,7 @@ UP018.py:25:1: UP018 [*] Unnecessary call to `bytes`
|
|||
|
|
||||
= help: Replace with empty bytes
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
22 22 | str("foo")
|
||||
23 23 | str("""
|
||||
24 24 | foo""")
|
||||
|
@ -98,7 +98,7 @@ UP018.py:26:1: UP018 [*] Unnecessary call to `bytes`
|
|||
|
|
||||
= help: Replace with empty bytes
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
23 23 | str("""
|
||||
24 24 | foo""")
|
||||
25 25 | bytes()
|
||||
|
@ -119,7 +119,7 @@ UP018.py:27:1: UP018 [*] Unnecessary call to `bytes`
|
|||
|
|
||||
= help: Replace with empty bytes
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
24 24 | foo""")
|
||||
25 25 | bytes()
|
||||
26 26 | bytes(b"foo")
|
||||
|
@ -138,7 +138,7 @@ UP018.py:29:4: UP018 [*] Unnecessary call to `str`
|
|||
|
|
||||
= help: Replace with empty string
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
26 26 | bytes(b"foo")
|
||||
27 27 | bytes(b"""
|
||||
28 28 | foo""")
|
||||
|
|
|
@ -10,7 +10,7 @@ UP033_0.py:4:21: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cac
|
|||
|
|
||||
= help: Rewrite with `@functools.cache
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
1 1 | import functools
|
||||
2 2 |
|
||||
3 3 |
|
||||
|
@ -30,7 +30,7 @@ UP033_0.py:10:21: UP033 [*] Use `@functools.cache` instead of `@functools.lru_ca
|
|||
|
|
||||
= help: Rewrite with `@functools.cache
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
7 7 |
|
||||
8 8 |
|
||||
9 9 | @other_decorator
|
||||
|
@ -49,7 +49,7 @@ UP033_0.py:15:21: UP033 [*] Use `@functools.cache` instead of `@functools.lru_ca
|
|||
|
|
||||
= help: Rewrite with `@functools.cache
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
12 12 | pass
|
||||
13 13 |
|
||||
14 14 |
|
||||
|
|
|
@ -10,7 +10,7 @@ UP033_1.py:4:11: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cac
|
|||
|
|
||||
= help: Rewrite with `@functools.cache
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
1 |-from functools import lru_cache
|
||||
1 |+from functools import lru_cache, cache
|
||||
2 2 |
|
||||
|
@ -31,7 +31,7 @@ UP033_1.py:10:11: UP033 [*] Use `@functools.cache` instead of `@functools.lru_ca
|
|||
|
|
||||
= help: Rewrite with `@functools.cache
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
1 |-from functools import lru_cache
|
||||
1 |+from functools import lru_cache, cache
|
||||
2 2 |
|
||||
|
@ -56,7 +56,7 @@ UP033_1.py:15:11: UP033 [*] Use `@functools.cache` instead of `@functools.lru_ca
|
|||
|
|
||||
= help: Rewrite with `@functools.cache
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
1 |-from functools import lru_cache
|
||||
1 |+from functools import lru_cache, cache
|
||||
2 2 |
|
||||
|
|
|
@ -11,7 +11,7 @@ UP034.py:2:7: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
1 1 | # UP034
|
||||
2 |-print(("foo"))
|
||||
2 |+print("foo")
|
||||
|
@ -29,7 +29,7 @@ UP034.py:5:7: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
2 2 | print(("foo"))
|
||||
3 3 |
|
||||
4 4 | # UP034
|
||||
|
@ -49,7 +49,7 @@ UP034.py:8:7: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
5 5 | print(("hell((goodybe))o"))
|
||||
6 6 |
|
||||
7 7 | # UP034
|
||||
|
@ -69,7 +69,7 @@ UP034.py:11:7: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
8 8 | print((("foo")))
|
||||
9 9 |
|
||||
10 10 | # UP034
|
||||
|
@ -89,7 +89,7 @@ UP034.py:14:7: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
11 11 | print((((1))))
|
||||
12 12 |
|
||||
13 13 | # UP034
|
||||
|
@ -109,7 +109,7 @@ UP034.py:18:5: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
15 15 |
|
||||
16 16 | # UP034
|
||||
17 17 | print(
|
||||
|
@ -132,7 +132,7 @@ UP034.py:23:5: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
20 20 |
|
||||
21 21 | # UP034
|
||||
22 22 | print(
|
||||
|
@ -156,7 +156,7 @@ UP034.py:30:13: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
27 27 |
|
||||
28 28 | # UP034
|
||||
29 29 | def f():
|
||||
|
@ -176,7 +176,7 @@ UP034.py:35:9: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
32 32 | # UP034
|
||||
33 33 | if True:
|
||||
34 34 | print(
|
||||
|
@ -196,7 +196,7 @@ UP034.py:39:7: UP034 [*] Avoid extraneous parentheses
|
|||
|
|
||||
= help: Remove extraneous parentheses
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Fix
|
||||
36 36 | )
|
||||
37 37 |
|
||||
38 38 | # UP034
|
||||
|
|
|
@ -10,7 +10,7 @@ future_annotations.py:40:4: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
37 37 | return y
|
||||
38 38 |
|
||||
39 39 |
|
||||
|
|
|
@ -10,7 +10,7 @@ future_annotations.py:40:4: UP007 [*] Use `X | Y` for type annotations
|
|||
|
|
||||
= help: Convert to `X | Y`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible 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`
|
||||
|
||||
ℹ Suggested fix
|
||||
ℹ Possible fix
|
||||
39 39 |
|
||||
40 40 | x: Optional[int] = None
|
||||
41 41 |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue