Skip to content

Commit 85a7edc

Browse files
charliermarshzanieb
authored andcommitted
Recategorize runtime-string-union to TCH010 (#9721)
## Summary This rule was added to `flake8-type-checking` as `TC010`. We're about to stabilize it, so we might as well use the correct code. See: #9573.
1 parent 7db3aea commit 85a7edc

12 files changed

+93
-91
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_1.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH006_2.py

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import annotations
2+
3+
from typing import TypeVar
4+
5+
6+
x: "int" | str # TCH010
7+
x: ("int" | str) | "bool" # TCH010
8+
9+
10+
def func():
11+
x: "int" | str # OK
12+
13+
14+
z: list[str, str | "int"] = [] # TCH010
15+
16+
type A = Value["int" | str] # OK
17+
18+
OldS = TypeVar('OldS', int | 'str', str) # TCH010
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import TypeVar
2+
3+
4+
x: "int" | str # TCH010
5+
x: ("int" | str) | "bool" # TCH010
6+
7+
8+
def func():
9+
x: "int" | str # OK
10+
11+
12+
z: list[str, str | "int"] = [] # TCH010
13+
14+
type A = Value["int" | str] # OK
15+
16+
OldS = TypeVar('OldS', int | 'str', str) # TCH010

crates/ruff_linter/src/codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
841841
(Flake8TypeChecking, "003") => (RuleGroup::Stable, rules::flake8_type_checking::rules::TypingOnlyStandardLibraryImport),
842842
(Flake8TypeChecking, "004") => (RuleGroup::Stable, rules::flake8_type_checking::rules::RuntimeImportInTypeCheckingBlock),
843843
(Flake8TypeChecking, "005") => (RuleGroup::Stable, rules::flake8_type_checking::rules::EmptyTypeCheckingBlock),
844-
(Flake8TypeChecking, "006") => (RuleGroup::Stable, rules::flake8_type_checking::rules::RuntimeStringUnion),
844+
(Flake8TypeChecking, "010") => (RuleGroup::Stable, rules::flake8_type_checking::rules::RuntimeStringUnion),
845845

846846
// tryceratops
847847
(Tryceratops, "002") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseVanillaClass),

crates/ruff_linter/src/rule_redirects.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
9999
("T003", "FIX003"),
100100
("T004", "FIX004"),
101101
("RUF011", "B035"),
102+
("TCH006", "TCH010"),
102103
])
103104
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ mod tests {
3535
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_8.py"))]
3636
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_9.py"))]
3737
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("quote.py"))]
38-
#[test_case(Rule::RuntimeStringUnion, Path::new("TCH006_1.py"))]
39-
#[test_case(Rule::RuntimeStringUnion, Path::new("TCH006_2.py"))]
38+
#[test_case(Rule::RuntimeStringUnion, Path::new("TCH010_1.py"))]
39+
#[test_case(Rule::RuntimeStringUnion, Path::new("TCH010_2.py"))]
4040
#[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TCH001.py"))]
4141
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TCH003.py"))]
4242
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("init_var.py"))]

crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_1.py.snap

Lines changed: 0 additions & 12 deletions
This file was deleted.

crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__runtime-string-union_TCH006_2.py.snap

Lines changed: 0 additions & 41 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
3+
---
4+
TCH010_1.py:18:30: TCH010 Invalid string member in `X | Y`-style union type
5+
|
6+
16 | type A = Value["int" | str] # OK
7+
17 |
8+
18 | OldS = TypeVar('OldS', int | 'str', str) # TCH010
9+
| ^^^^^ TCH010
10+
|
11+
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
3+
---
4+
TCH010_2.py:4:4: TCH010 Invalid string member in `X | Y`-style union type
5+
|
6+
4 | x: "int" | str # TCH010
7+
| ^^^^^ TCH010
8+
5 | x: ("int" | str) | "bool" # TCH010
9+
|
10+
11+
TCH010_2.py:5:5: TCH010 Invalid string member in `X | Y`-style union type
12+
|
13+
4 | x: "int" | str # TCH010
14+
5 | x: ("int" | str) | "bool" # TCH010
15+
| ^^^^^ TCH010
16+
|
17+
18+
TCH010_2.py:5:20: TCH010 Invalid string member in `X | Y`-style union type
19+
|
20+
4 | x: "int" | str # TCH010
21+
5 | x: ("int" | str) | "bool" # TCH010
22+
| ^^^^^^ TCH010
23+
|
24+
25+
TCH010_2.py:12:20: TCH010 Invalid string member in `X | Y`-style union type
26+
|
27+
12 | z: list[str, str | "int"] = [] # TCH010
28+
| ^^^^^ TCH010
29+
13 |
30+
14 | type A = Value["int" | str] # OK
31+
|
32+
33+
TCH010_2.py:16:30: TCH010 Invalid string member in `X | Y`-style union type
34+
|
35+
14 | type A = Value["int" | str] # OK
36+
15 |
37+
16 | OldS = TypeVar('OldS', int | 'str', str) # TCH010
38+
| ^^^^^ TCH010
39+
|
40+
41+

ruff.schema.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)