Skip to content

Commit

Permalink
Revert "Add all PEP-585 names to UP006 rule" (#15250)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Jan 4, 2025
1 parent baf0d66 commit e4d9fe0
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 649 deletions.
64 changes: 0 additions & 64 deletions crates/ruff/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,67 +2126,3 @@ unfixable = ["RUF"]

Ok(())
}

#[test]
fn verbose_show_failed_fix_errors() {
let mut cmd = RuffCheck::default()
.args(["--select", "UP006", "--preview", "-v"])
.build();

insta::with_settings!(
{
// the logs have timestamps we need to remove
filters => vec![(
r"\[[\d:-]+]",
""
)]
},{
assert_cmd_snapshot!(cmd
.pass_stdin("import typing\nCallable = 'abc'\ndef g() -> typing.Callable: ..."),
@r###"
success: false
exit_code: 1
----- stdout -----
-:3:12: UP006 Use `collections.abc.Callable` instead of `typing.Callable` for type annotation
|
1 | import typing
2 | Callable = 'abc'
3 | def g() -> typing.Callable: ...
| ^^^^^^^^^^^^^^^ UP006
|
= help: Replace with `collections.abc.Callable`
Found 1 error.
----- stderr -----
[ruff::resolve][DEBUG] Isolated mode, not reading any pyproject.toml
[ruff_diagnostics::diagnostic][DEBUG] Failed to create fix for NonPEP585Annotation: Unable to insert `Callable` into scope due to name conflict
"###); }
);
}

#[test]
fn no_verbose_hide_failed_fix_errors() {
let mut cmd = RuffCheck::default()
.args(["--select", "UP006", "--preview"])
.build();
assert_cmd_snapshot!(cmd
.pass_stdin("import typing\nCallable = 'abc'\ndef g() -> typing.Callable: ..."),
@r###"
success: false
exit_code: 1
----- stdout -----
-:3:12: UP006 Use `collections.abc.Callable` instead of `typing.Callable` for type annotation
|
1 | import typing
2 | Callable = 'abc'
3 | def g() -> typing.Callable: ...
| ^^^^^^^^^^^^^^^ UP006
|
= help: Replace with `collections.abc.Callable`
Found 1 error.
----- stderr -----
"###);
}
19 changes: 0 additions & 19 deletions crates/ruff_linter/resources/test/fixtures/pyupgrade/UP006_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,3 @@ def f(x: typing.Deque[str]) -> None:

def f(x: typing.DefaultDict[str, str]) -> None:
...


def f(x: typing.AbstractSet[str]) -> None:
...


def f(x: typing.Pattern[str]) -> None:
...


def f(x: typing.Sequence[str]) -> None:
...


from typing import Collection


def f(x: typing.Collection[str]) -> None:
...
16 changes: 0 additions & 16 deletions crates/ruff_linter/resources/test/fixtures/pyupgrade/UP006_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,3 @@

def f(x: typing.DefaultDict[str, str]) -> None:
...


from collections.abc import Set
from typing_extensions import Awaitable


def f(x: typing.AbstractSet[str]) -> None:
...


def f(x: Set) -> None:
...


def f(x: Awaitable) -> None:
...
15 changes: 0 additions & 15 deletions crates/ruff_linter/src/rules/pyupgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,6 @@ mod tests {
Ok(())
}

#[test_case(Rule::NonPEP585Annotation, Path::new("UP006_0.py"))]
#[test_case(Rule::NonPEP585Annotation, Path::new("UP006_1.py"))]
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("preview__{}", path.to_string_lossy());
let diagnostics = test_path(
Path::new("pyupgrade").join(path).as_path(),
&settings::LinterSettings {
preview: PreviewMode::Enabled,
..settings::LinterSettings::for_rule(rule_code)
},
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
}

#[test]
fn async_timeout_error_alias_not_applied_py310() -> Result<()> {
let diagnostics = test_path(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ use crate::settings::types::PythonVersion;
/// Checks for the use of generics that can be replaced with standard library
/// variants based on [PEP 585].
///
/// Under [preview mode](https://docs.astral.sh/ruff/preview),
/// this rule triggers for all replacements listed
/// in [PEP 585]. Otherwise, this rule only triggers for the following
/// commonly occurring instances of modules present in the
/// `typing` or `typing_extensions` package:
///
/// - `Dict`
/// - `FrozenSet`
/// - `List`
/// - `Set`
/// - `Tuple`
/// - `Type`
/// - `Deque`
/// - `DefaultDict`
///
/// ## Why is this bad?
/// [PEP 585] enabled collections in the Python standard library (like `list`)
/// to be used as generics directly, instead of importing analogous members
Expand Down Expand Up @@ -96,9 +81,6 @@ pub(crate) fn use_pep585_annotation(
expr: &Expr,
replacement: &ModuleMember,
) {
if !checker.settings.preview.is_enabled() && !is_restricted_pep585_generic(replacement) {
return;
}
let Some(from) = UnqualifiedName::from_expr(expr) else {
return;
};
Expand Down Expand Up @@ -156,11 +138,3 @@ pub(crate) fn use_pep585_annotation(
}
checker.diagnostics.push(diagnostic);
}

fn is_restricted_pep585_generic(module_member: &ModuleMember) -> bool {
matches!(
module_member,
ModuleMember::BuiltIn("dict" | "frozenset" | "list" | "set" | "tuple" | "type")
| ModuleMember::Member("collections", "deque" | "defaultdict")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,3 @@ UP006_0.py:65:10: UP006 [*] Use `collections.defaultdict` instead of `typing.Def
65 |-def f(x: typing.DefaultDict[str, str]) -> None:
66 |+def f(x: defaultdict[str, str]) -> None:
66 67 | ...
67 68 |
68 69 |
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ UP006_1.py:9:10: UP006 [*] Use `collections.defaultdict` instead of `typing.Defa
9 |-def f(x: typing.DefaultDict[str, str]) -> None:
9 |+def f(x: defaultdict[str, str]) -> None:
10 10 | ...
11 11 |
12 12 |
Loading

0 comments on commit e4d9fe0

Please sign in to comment.