Skip to content

Commit

Permalink
Change applicability to suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Jun 17, 2023
1 parent 736a315 commit 6bfcb1a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
let mut diagnostic = Diagnostic::new(DeprecatedCElementTree, node.range());
if checker.patch(diagnostic.kind.rule()) {
let contents = checker.locator.slice(node.range());
diagnostic.set_fix(Fix::manual(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
contents.replacen("cElementTree", "ElementTree", 1),
node.range(),
)));
Expand Down
5 changes: 4 additions & 1 deletion crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,10 @@ pub(crate) fn deprecated_import(
);
if checker.patch(Rule::DeprecatedImport) {
if let Some(content) = fix {
diagnostic.set_fix(Fix::manual(Edit::range_replacement(content, stmt.range())));
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
content,
stmt.range(),
)));
}
}
checker.diagnostics.push(diagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub(crate) fn deprecated_mock_attribute(checker: &mut Checker, expr: &Expr) {
value.range(),
);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::manual(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
"mock".to_string(),
value.range(),
)));
Expand Down Expand Up @@ -306,7 +306,7 @@ pub(crate) fn deprecated_mock_import(checker: &mut Checker, stmt: &Stmt) {
name.range(),
);
if let Some(content) = content.as_ref() {
diagnostic.set_fix(Fix::manual(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
content.clone(),
stmt.range(),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ UP023.py:2:1: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
1 1 | # These two imports have something after cElementTree, so they should be fixed.
2 |-from xml.etree.cElementTree import XML, Element, SubElement
2 |+from xml.etree.ElementTree import XML, Element, SubElement
Expand All @@ -29,7 +29,7 @@ UP023.py:3:8: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
1 1 | # These two imports have something after cElementTree, so they should be fixed.
2 2 | from xml.etree.cElementTree import XML, Element, SubElement
3 |-import xml.etree.cElementTree as ET
Expand All @@ -47,7 +47,7 @@ UP023.py:6:1: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
3 3 | import xml.etree.cElementTree as ET
4 4 |
5 5 | # Weird spacing should not cause issues.
Expand All @@ -68,7 +68,7 @@ UP023.py:7:11: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
4 4 |
5 5 | # Weird spacing should not cause issues.
6 6 | from xml.etree.cElementTree import XML
Expand All @@ -92,7 +92,7 @@ UP023.py:10:1: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
7 7 | import xml.etree.cElementTree as ET
8 8 |
9 9 | # Multi line imports should also work fine.
Expand All @@ -112,7 +112,7 @@ UP023.py:16:12: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
13 13 | SubElement,
14 14 | )
15 15 | if True:
Expand All @@ -133,7 +133,7 @@ UP023.py:17:27: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
14 14 | )
15 15 | if True:
16 16 | import xml.etree.cElementTree as ET
Expand All @@ -154,7 +154,7 @@ UP023.py:19:23: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
16 16 | import xml.etree.cElementTree as ET
17 17 | from xml.etree import cElementTree as CET
18 18 |
Expand All @@ -175,7 +175,7 @@ UP023.py:21:20: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
18 18 |
19 19 | from xml.etree import cElementTree as ET
20 20 |
Expand All @@ -195,7 +195,7 @@ UP023.py:24:32: UP023 [*] `cElementTree` is deprecated, use `ElementTree`
|
= help: Replace with `ElementTree`

Possible fix
Suggested fix
21 21 | import contextlib, xml.etree.cElementTree as ET
22 22 |
23 23 | # This should fix the second, but not the first invocation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ UP026.py:3:12: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
1 1 | # Error (`from unittest import mock`)
2 2 | if True:
3 |- import mock
Expand All @@ -32,7 +32,7 @@ UP026.py:7:12: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
4 4 |
5 5 | # Error (`from unittest import mock`)
6 6 | if True:
Expand Down Expand Up @@ -74,7 +74,7 @@ UP026.py:14:8: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
11 11 | from mock import *
12 12 |
13 13 | # Error (`from unittest import mock`)
Expand All @@ -94,7 +94,7 @@ UP026.py:17:20: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
14 14 | import mock.mock
15 15 |
16 16 | # Error (`from unittest import mock`)
Expand All @@ -114,7 +114,7 @@ UP026.py:20:8: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
17 17 | import contextlib, mock, sys
18 18 |
19 19 | # Error (`from unittest import mock`)
Expand Down Expand Up @@ -358,7 +358,7 @@ UP026.py:69:8: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
66 66 | import os, io
67 67 |
68 68 | # Error (`from unittest import mock`)
Expand All @@ -379,7 +379,7 @@ UP026.py:69:14: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
66 66 | import os, io
67 67 |
68 68 | # Error (`from unittest import mock`)
Expand All @@ -400,7 +400,7 @@ UP026.py:72:8: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
69 69 | import mock, mock
70 70 |
71 71 | # Error (`from unittest import mock as foo`)
Expand Down Expand Up @@ -441,7 +441,7 @@ UP026.py:79:12: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
76 76 |
77 77 | if True:
78 78 | # This should yield multiple, aliased imports.
Expand All @@ -464,7 +464,7 @@ UP026.py:79:25: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
76 76 |
77 77 | if True:
78 78 | # This should yield multiple, aliased imports.
Expand All @@ -487,7 +487,7 @@ UP026.py:79:38: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
76 76 |
77 77 | if True:
78 78 | # This should yield multiple, aliased imports.
Expand All @@ -509,7 +509,7 @@ UP026.py:82:12: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
79 79 | import mock as foo, mock as bar, mock
80 80 |
81 81 | # This should yield multiple, aliased imports, and preserve `os`.
Expand All @@ -532,7 +532,7 @@ UP026.py:82:25: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
79 79 | import mock as foo, mock as bar, mock
80 80 |
81 81 | # This should yield multiple, aliased imports, and preserve `os`.
Expand All @@ -555,7 +555,7 @@ UP026.py:82:38: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Import from `unittest.mock` instead

Possible fix
Suggested fix
79 79 | import mock as foo, mock as bar, mock
80 80 |
81 81 | # This should yield multiple, aliased imports, and preserve `os`.
Expand Down Expand Up @@ -597,7 +597,7 @@ UP026.py:93:5: UP026 [*] `mock` is deprecated, use `unittest.mock`
|
= help: Replace `mock.mock` with `mock`

Possible fix
Suggested fix
90 90 | x = mock.Mock()
91 91 |
92 92 | # Error (`mock.Mock()`).
Expand Down
Loading

0 comments on commit 6bfcb1a

Please sign in to comment.