Skip to content

Commit

Permalink
Recategorize runtime-string-union to TCH010 (#9721)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
charliermarsh authored and zanieb committed Feb 1, 2024
1 parent c1e6732 commit 28672fe
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 91 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rule_redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
("T003", "FIX003"),
("T004", "FIX004"),
("RUF011", "B035"),
("TCH006", "TCH010"),
])
});
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
|


Original file line number Diff line number Diff line change
@@ -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
|


3 changes: 2 additions & 1 deletion ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 28672fe

Please sign in to comment.