From 6bfcb1a4de8c71e3437968dcda16f5faf70686fd Mon Sep 17 00:00:00 2001 From: Evan Rittenhouse Date: Sat, 17 Jun 2023 14:06:05 -0500 Subject: [PATCH] Change applicability to suggested --- .../rules/deprecated_c_element_tree.rs | 2 +- .../pyupgrade/rules/deprecated_import.rs | 5 ++- .../pyupgrade/rules/deprecated_mock_import.rs | 4 +-- ...ff__rules__pyupgrade__tests__UP023.py.snap | 20 +++++------ ...ff__rules__pyupgrade__tests__UP026.py.snap | 30 ++++++++-------- ...ff__rules__pyupgrade__tests__UP035.py.snap | 34 +++++++++---------- 6 files changed, 49 insertions(+), 46 deletions(-) diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs index f9457091c06aca..fed0bda549d526 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs @@ -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(), ))); diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs index 4f4d6efa643e17..335354234cc837 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_import.rs @@ -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); diff --git a/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs b/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs index 81a7fdfac45b20..30ecd488e5258b 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/deprecated_mock_import.rs @@ -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(), ))); @@ -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(), ))); diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap index c591e9174c4530..3f6e5169e89a6c 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap @@ -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 @@ -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 @@ -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. @@ -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 @@ -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. @@ -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: @@ -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 @@ -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 | @@ -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 | @@ -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. diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap index 6a289653c0f7f7..a2f7f589be1b74 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap @@ -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 @@ -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: @@ -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`) @@ -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`) @@ -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`) @@ -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`) @@ -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`) @@ -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`) @@ -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. @@ -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. @@ -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. @@ -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`. @@ -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`. @@ -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`. @@ -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()`). diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap index c33ad736a3cd1e..e9c2076aeddd54 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap @@ -11,7 +11,7 @@ UP035.py:2:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 1 1 | # UP035 2 |-from collections import Mapping 2 |+from collections.abc import Mapping @@ -30,7 +30,7 @@ UP035.py:4:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 1 1 | # UP035 2 2 | from collections import Mapping 3 3 | @@ -51,7 +51,7 @@ UP035.py:6:1: UP035 [*] Import from `collections.abc` instead: `Mapping`, `Seque | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 3 3 | 4 4 | from collections import Mapping as MAP 5 5 | @@ -72,7 +72,7 @@ UP035.py:8:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 5 5 | 6 6 | from collections import Mapping, Sequence 7 7 | @@ -94,7 +94,7 @@ UP035.py:10:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 7 7 | 8 8 | from collections import Counter, Mapping 9 9 | @@ -117,7 +117,7 @@ UP035.py:12:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 9 9 | 10 10 | from collections import (Counter, Mapping) 11 11 | @@ -141,7 +141,7 @@ UP035.py:15:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 12 12 | from collections import (Counter, 13 13 | Mapping) 14 14 | @@ -164,7 +164,7 @@ UP035.py:18:1: UP035 [*] Import from `collections.abc` instead: `Mapping`, `Sequ | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 15 15 | from collections import Counter, \ 16 16 | Mapping 17 17 | @@ -186,7 +186,7 @@ UP035.py:20:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 17 17 | 18 18 | from collections import Counter, Mapping, Sequence 19 19 | @@ -207,7 +207,7 @@ UP035.py:23:5: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 20 20 | from collections import Mapping as mapping, Counter 21 21 | 22 22 | if True: @@ -229,7 +229,7 @@ UP035.py:28:5: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 25 25 | if True: 26 26 | if True: 27 27 | pass @@ -251,7 +251,7 @@ UP035.py:30:10: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 27 27 | pass 28 28 | from collections import Mapping, Counter 29 29 | @@ -270,7 +270,7 @@ UP035.py:33:1: UP035 [*] Import from `collections.abc` instead: `Mapping` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 30 30 | if True: from collections import Mapping 31 31 | 32 32 | import os @@ -297,7 +297,7 @@ UP035.py:37:5: UP035 [*] Import from `collections.abc` instead: `Mapping`, `Call | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 35 35 | 36 36 | if True: 37 37 | from collections import ( @@ -322,7 +322,7 @@ UP035.py:44:1: UP035 [*] Import from `collections.abc` instead: `Callable` | = help: Import from `collections.abc` -ℹ Possible fix +ℹ Suggested fix 41 41 | Good, 42 42 | ) 43 43 | @@ -344,7 +344,7 @@ UP035.py:44:1: UP035 [*] Import from `collections` instead: `OrderedDict` | = help: Import from `collections` -ℹ Possible fix +ℹ Suggested fix 41 41 | Good, 42 42 | ) 43 43 | @@ -366,7 +366,7 @@ UP035.py:44:1: UP035 [*] Import from `re` instead: `Match`, `Pattern` | = help: Import from `re` -ℹ Possible fix +ℹ Suggested fix 41 41 | Good, 42 42 | ) 43 43 |