mirror of https://github.com/astral-sh/ruff
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: https://github.com/astral-sh/ruff/issues/9573.
This commit is contained in:
parent
c1e673248d
commit
28672fef4b
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -99,5 +99,6 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
|
|||
("T003", "FIX003"),
|
||||
("T004", "FIX004"),
|
||||
("RUF011", "B035"),
|
||||
("TCH006", "TCH010"),
|
||||
])
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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"))]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
|
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
|
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
|
|
||||
|
||||
|
||||
|
|
@ -3687,7 +3687,8 @@
|
|||
"TCH003",
|
||||
"TCH004",
|
||||
"TCH005",
|
||||
"TCH006",
|
||||
"TCH01",
|
||||
"TCH010",
|
||||
"TD",
|
||||
"TD0",
|
||||
"TD00",
|
||||
|
|
|
|||
Loading…
Reference in New Issue