Skip to content

Commit e4d9fe0

Browse files
authored
Revert "Add all PEP-585 names to UP006 rule" (#15250)
1 parent baf0d66 commit e4d9fe0

11 files changed

+19
-649
lines changed

crates/ruff/tests/integration_test.rs

-64
Original file line numberDiff line numberDiff line change
@@ -2126,67 +2126,3 @@ unfixable = ["RUF"]
21262126

21272127
Ok(())
21282128
}
2129-
2130-
#[test]
2131-
fn verbose_show_failed_fix_errors() {
2132-
let mut cmd = RuffCheck::default()
2133-
.args(["--select", "UP006", "--preview", "-v"])
2134-
.build();
2135-
2136-
insta::with_settings!(
2137-
{
2138-
// the logs have timestamps we need to remove
2139-
filters => vec![(
2140-
r"\[[\d:-]+]",
2141-
""
2142-
)]
2143-
},{
2144-
assert_cmd_snapshot!(cmd
2145-
.pass_stdin("import typing\nCallable = 'abc'\ndef g() -> typing.Callable: ..."),
2146-
@r###"
2147-
success: false
2148-
exit_code: 1
2149-
----- stdout -----
2150-
-:3:12: UP006 Use `collections.abc.Callable` instead of `typing.Callable` for type annotation
2151-
|
2152-
1 | import typing
2153-
2 | Callable = 'abc'
2154-
3 | def g() -> typing.Callable: ...
2155-
| ^^^^^^^^^^^^^^^ UP006
2156-
|
2157-
= help: Replace with `collections.abc.Callable`
2158-
2159-
Found 1 error.
2160-
2161-
----- stderr -----
2162-
[ruff::resolve][DEBUG] Isolated mode, not reading any pyproject.toml
2163-
[ruff_diagnostics::diagnostic][DEBUG] Failed to create fix for NonPEP585Annotation: Unable to insert `Callable` into scope due to name conflict
2164-
"###); }
2165-
);
2166-
}
2167-
2168-
#[test]
2169-
fn no_verbose_hide_failed_fix_errors() {
2170-
let mut cmd = RuffCheck::default()
2171-
.args(["--select", "UP006", "--preview"])
2172-
.build();
2173-
assert_cmd_snapshot!(cmd
2174-
.pass_stdin("import typing\nCallable = 'abc'\ndef g() -> typing.Callable: ..."),
2175-
@r###"
2176-
success: false
2177-
exit_code: 1
2178-
----- stdout -----
2179-
-:3:12: UP006 Use `collections.abc.Callable` instead of `typing.Callable` for type annotation
2180-
|
2181-
1 | import typing
2182-
2 | Callable = 'abc'
2183-
3 | def g() -> typing.Callable: ...
2184-
| ^^^^^^^^^^^^^^^ UP006
2185-
|
2186-
= help: Replace with `collections.abc.Callable`
2187-
2188-
Found 1 error.
2189-
2190-
----- stderr -----
2191-
"###);
2192-
}

crates/ruff_linter/resources/test/fixtures/pyupgrade/UP006_0.py

-19
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,3 @@ def f(x: typing.Deque[str]) -> None:
6464

6565
def f(x: typing.DefaultDict[str, str]) -> None:
6666
...
67-
68-
69-
def f(x: typing.AbstractSet[str]) -> None:
70-
...
71-
72-
73-
def f(x: typing.Pattern[str]) -> None:
74-
...
75-
76-
77-
def f(x: typing.Sequence[str]) -> None:
78-
...
79-
80-
81-
from typing import Collection
82-
83-
84-
def f(x: typing.Collection[str]) -> None:
85-
...

crates/ruff_linter/resources/test/fixtures/pyupgrade/UP006_1.py

-16
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,3 @@
88

99
def f(x: typing.DefaultDict[str, str]) -> None:
1010
...
11-
12-
13-
from collections.abc import Set
14-
from typing_extensions import Awaitable
15-
16-
17-
def f(x: typing.AbstractSet[str]) -> None:
18-
...
19-
20-
21-
def f(x: Set) -> None:
22-
...
23-
24-
25-
def f(x: Awaitable) -> None:
26-
...

crates/ruff_linter/src/rules/pyupgrade/mod.rs

-15
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,6 @@ mod tests {
111111
Ok(())
112112
}
113113

114-
#[test_case(Rule::NonPEP585Annotation, Path::new("UP006_0.py"))]
115-
#[test_case(Rule::NonPEP585Annotation, Path::new("UP006_1.py"))]
116-
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
117-
let snapshot = format!("preview__{}", path.to_string_lossy());
118-
let diagnostics = test_path(
119-
Path::new("pyupgrade").join(path).as_path(),
120-
&settings::LinterSettings {
121-
preview: PreviewMode::Enabled,
122-
..settings::LinterSettings::for_rule(rule_code)
123-
},
124-
)?;
125-
assert_messages!(snapshot, diagnostics);
126-
Ok(())
127-
}
128-
129114
#[test]
130115
fn async_timeout_error_alias_not_applied_py310() -> Result<()> {
131116
let diagnostics = test_path(

crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs

-26
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ use crate::settings::types::PythonVersion;
1414
/// Checks for the use of generics that can be replaced with standard library
1515
/// variants based on [PEP 585].
1616
///
17-
/// Under [preview mode](https://docs.astral.sh/ruff/preview),
18-
/// this rule triggers for all replacements listed
19-
/// in [PEP 585]. Otherwise, this rule only triggers for the following
20-
/// commonly occurring instances of modules present in the
21-
/// `typing` or `typing_extensions` package:
22-
///
23-
/// - `Dict`
24-
/// - `FrozenSet`
25-
/// - `List`
26-
/// - `Set`
27-
/// - `Tuple`
28-
/// - `Type`
29-
/// - `Deque`
30-
/// - `DefaultDict`
31-
///
3217
/// ## Why is this bad?
3318
/// [PEP 585] enabled collections in the Python standard library (like `list`)
3419
/// to be used as generics directly, instead of importing analogous members
@@ -96,9 +81,6 @@ pub(crate) fn use_pep585_annotation(
9681
expr: &Expr,
9782
replacement: &ModuleMember,
9883
) {
99-
if !checker.settings.preview.is_enabled() && !is_restricted_pep585_generic(replacement) {
100-
return;
101-
}
10284
let Some(from) = UnqualifiedName::from_expr(expr) else {
10385
return;
10486
};
@@ -156,11 +138,3 @@ pub(crate) fn use_pep585_annotation(
156138
}
157139
checker.diagnostics.push(diagnostic);
158140
}
159-
160-
fn is_restricted_pep585_generic(module_member: &ModuleMember) -> bool {
161-
matches!(
162-
module_member,
163-
ModuleMember::BuiltIn("dict" | "frozenset" | "list" | "set" | "tuple" | "type")
164-
| ModuleMember::Member("collections", "deque" | "defaultdict")
165-
)
166-
}

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP006_0.py.snap

-2
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,3 @@ UP006_0.py:65:10: UP006 [*] Use `collections.defaultdict` instead of `typing.Def
281281
65 |-def f(x: typing.DefaultDict[str, str]) -> None:
282282
66 |+def f(x: defaultdict[str, str]) -> None:
283283
66 67 | ...
284-
67 68 |
285-
68 69 |

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP006_1.py.snap

-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ UP006_1.py:9:10: UP006 [*] Use `collections.defaultdict` instead of `typing.Defa
1717
9 |-def f(x: typing.DefaultDict[str, str]) -> None:
1818
9 |+def f(x: defaultdict[str, str]) -> None:
1919
10 10 | ...
20-
11 11 |
21-
12 12 |

0 commit comments

Comments
 (0)