diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_1.py b/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_1.py deleted file mode 100644 index 7e8df4ce10..0000000000 --- a/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_1.py +++ /dev/null @@ -1,18 +0,0 @@ -from __future__ import annotations - -from typing import TypeVar - - -x: "int" | str # TCH006 -x: ("int" | str) | "bool" # TCH006 - - -def func(): - x: "int" | str # OK - - -z: list[str, str | "int"] = [] # TCH006 - -type A = Value["int" | str] # OK - -OldS = TypeVar('OldS', int | 'str', str) # TCH006 diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_2.py b/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_2.py deleted file mode 100644 index 0c7d5915b7..0000000000 --- a/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_2.py +++ /dev/null @@ -1,16 +0,0 @@ -from typing import TypeVar - - -x: "int" | str # TCH006 -x: ("int" | str) | "bool" # TCH006 - - -def func(): - x: "int" | str # OK - - -z: list[str, str | "int"] = [] # TCH006 - -type A = Value["int" | str] # OK - -OldS = TypeVar('OldS', int | 'str', str) # TCH006 diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH010_1.py b/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH010_1.py new file mode 100644 index 0000000000..d640994930 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH010_1.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from typing import TypeVar + + +x: "int" | str # TCH010 +x: ("int" | str) | "bool" # TCH010 + + +def func(): + x: "int" | str # OK + + +z: list[str, str | "int"] = [] # TCH010 + +type A = Value["int" | str] # OK + +OldS = TypeVar('OldS', int | 'str', str) # TCH010 diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH010_2.py b/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH010_2.py new file mode 100644 index 0000000000..09fae9a5e6 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH010_2.py @@ -0,0 +1,16 @@ +from typing import TypeVar + + +x: "int" | str # TCH010 +x: ("int" | str) | "bool" # TCH010 + + +def func(): + x: "int" | str # OK + + +z: list[str, str | "int"] = [] # TCH010 + +type A = Value["int" | str] # OK + +OldS = TypeVar('OldS', int | 'str', str) # TCH010 diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 750495772d..6ba3d90e66 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -841,7 +841,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8TypeChecking, "003") => (RuleGroup::Stable, rules::flake8_type_checking::rules::TypingOnlyStandardLibraryImport), (Flake8TypeChecking, "004") => (RuleGroup::Stable, rules::flake8_type_checking::rules::RuntimeImportInTypeCheckingBlock), (Flake8TypeChecking, "005") => (RuleGroup::Stable, rules::flake8_type_checking::rules::EmptyTypeCheckingBlock), - (Flake8TypeChecking, "006") => (RuleGroup::Stable, rules::flake8_type_checking::rules::RuntimeStringUnion), + (Flake8TypeChecking, "010") => (RuleGroup::Stable, rules::flake8_type_checking::rules::RuntimeStringUnion), // tryceratops (Tryceratops, "002") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseVanillaClass), diff --git a/crates/ruff_linter/src/rule_redirects.rs b/crates/ruff_linter/src/rule_redirects.rs index 7115a252a9..12408c56bd 100644 --- a/crates/ruff_linter/src/rule_redirects.rs +++ b/crates/ruff_linter/src/rule_redirects.rs @@ -99,5 +99,6 @@ static REDIRECTS: Lazy> = Lazy::new(|| { ("T003", "FIX003"), ("T004", "FIX004"), ("RUF011", "B035"), + ("TCH006", "TCH010"), ]) }); diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs b/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs index ef105e99ff..ed513d3236 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs @@ -35,8 +35,8 @@ mod tests { #[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_8.py"))] #[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_9.py"))] #[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("quote.py"))] - #[test_case(Rule::RuntimeStringUnion, Path::new("TCH006_1.py"))] - #[test_case(Rule::RuntimeStringUnion, Path::new("TCH006_2.py"))] + #[test_case(Rule::RuntimeStringUnion, Path::new("TCH010_1.py"))] + #[test_case(Rule::RuntimeStringUnion, Path::new("TCH010_2.py"))] #[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TCH001.py"))] #[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TCH003.py"))] #[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("init_var.py"))] diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_1.py.snap b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_1.py.snap deleted file mode 100644 index 4ab8798d51..0000000000 --- a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_1.py.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs ---- -TCH006_1.py:18:30: TCH006 Invalid string member in `X | Y`-style union type - | -16 | type A = Value["int" | str] # OK -17 | -18 | OldS = TypeVar('OldS', int | 'str', str) # TCH006 - | ^^^^^ TCH006 - | - - diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_2.py.snap b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_2.py.snap deleted file mode 100644 index 8a2023ed44..0000000000 --- a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_2.py.snap +++ /dev/null @@ -1,41 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs ---- -TCH006_2.py:4:4: TCH006 Invalid string member in `X | Y`-style union type - | -4 | x: "int" | str # TCH006 - | ^^^^^ TCH006 -5 | x: ("int" | str) | "bool" # TCH006 - | - -TCH006_2.py:5:5: TCH006 Invalid string member in `X | Y`-style union type - | -4 | x: "int" | str # TCH006 -5 | x: ("int" | str) | "bool" # TCH006 - | ^^^^^ TCH006 - | - -TCH006_2.py:5:20: TCH006 Invalid string member in `X | Y`-style union type - | -4 | x: "int" | str # TCH006 -5 | x: ("int" | str) | "bool" # TCH006 - | ^^^^^^ TCH006 - | - -TCH006_2.py:12:20: TCH006 Invalid string member in `X | Y`-style union type - | -12 | z: list[str, str | "int"] = [] # TCH006 - | ^^^^^ TCH006 -13 | -14 | type A = Value["int" | str] # OK - | - -TCH006_2.py:16:30: TCH006 Invalid string member in `X | Y`-style union type - | -14 | type A = Value["int" | str] # OK -15 | -16 | OldS = TypeVar('OldS', int | 'str', str) # TCH006 - | ^^^^^ TCH006 - | - - diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH010_1.py.snap b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH010_1.py.snap new file mode 100644 index 0000000000..bf78da6c60 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH010_1.py.snap @@ -0,0 +1,12 @@ +--- +source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs +--- +TCH010_1.py:18:30: TCH010 Invalid string member in `X | Y`-style union type + | +16 | type A = Value["int" | str] # OK +17 | +18 | OldS = TypeVar('OldS', int | 'str', str) # TCH010 + | ^^^^^ TCH010 + | + + diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH010_2.py.snap b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH010_2.py.snap new file mode 100644 index 0000000000..f03037ad82 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH010_2.py.snap @@ -0,0 +1,41 @@ +--- +source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs +--- +TCH010_2.py:4:4: TCH010 Invalid string member in `X | Y`-style union type + | +4 | x: "int" | str # TCH010 + | ^^^^^ TCH010 +5 | x: ("int" | str) | "bool" # TCH010 + | + +TCH010_2.py:5:5: TCH010 Invalid string member in `X | Y`-style union type + | +4 | x: "int" | str # TCH010 +5 | x: ("int" | str) | "bool" # TCH010 + | ^^^^^ TCH010 + | + +TCH010_2.py:5:20: TCH010 Invalid string member in `X | Y`-style union type + | +4 | x: "int" | str # TCH010 +5 | x: ("int" | str) | "bool" # TCH010 + | ^^^^^^ TCH010 + | + +TCH010_2.py:12:20: TCH010 Invalid string member in `X | Y`-style union type + | +12 | z: list[str, str | "int"] = [] # TCH010 + | ^^^^^ TCH010 +13 | +14 | type A = Value["int" | str] # OK + | + +TCH010_2.py:16:30: TCH010 Invalid string member in `X | Y`-style union type + | +14 | type A = Value["int" | str] # OK +15 | +16 | OldS = TypeVar('OldS', int | 'str', str) # TCH010 + | ^^^^^ TCH010 + | + + diff --git a/ruff.schema.json b/ruff.schema.json index 49ee661d7c..2d73566f2d 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3687,7 +3687,8 @@ "TCH003", "TCH004", "TCH005", - "TCH006", + "TCH01", + "TCH010", "TD", "TD0", "TD00",