Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ruff 0.8][flake8-type-checking] Rename TCH to TC #14438

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/red_knot_workspace/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ const KNOWN_FAILURES: &[(&str, bool, bool)] = &[
("crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI063.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI064.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI064.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH004_13.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH004_13.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH004_15.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TCH004_15.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TC004_13.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TC004_13.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TC004_15.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/TC004_15.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/quote.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/quote.py", true, true),
("crates/ruff_linter/resources/test/fixtures/flake8_type_checking/quote2.py", true, true),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests to determine first-party import classification.

For typing-only import detection tests, see `TCH002.py`.
For typing-only import detection tests, see `TC002.py`.
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@


def f():
import pandas as pd # TCH002
import pandas as pd # TC002

x: pd.DataFrame


def f():
from pandas import DataFrame # TCH002
from pandas import DataFrame # TC002

x: DataFrame


def f():
from pandas import DataFrame as df # TCH002
from pandas import DataFrame as df # TC002

x: df


def f():
import pandas as pd # TCH002
import pandas as pd # TC002

x: pd.DataFrame = 1


def f():
from pandas import DataFrame # TCH002
from pandas import DataFrame # TC002

x: DataFrame = 2


def f():
from pandas import DataFrame as df # TCH002
from pandas import DataFrame as df # TC002

x: df = 3


def f():
import pandas as pd # TCH002
import pandas as pd # TC002

x: "pd.DataFrame" = 1


def f():
import pandas as pd # TCH002
import pandas as pd # TC002

x = dict["pd.DataFrame", "pd.DataFrame"]

Expand Down Expand Up @@ -153,13 +153,13 @@ def f():


def f():
from pandas import DataFrame # noqa: TCH002
from pandas import DataFrame # noqa: TC002

x: DataFrame = 2


def f():
from pandas import ( # noqa: TCH002
from pandas import ( # noqa: TC002
DataFrame,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests to determine standard library import classification.

For typing-only import detection tests, see `TCH002.py`.
For typing-only import detection tests, see `TC002.py`.
"""


Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from typing import TYPE_CHECKING, List

if TYPE_CHECKING:
pass # TCH005
pass # TC005


if False:
pass # TCH005
pass # TC005

if 0:
pass # TCH005
pass # TC005


def example():
if TYPE_CHECKING:
pass # TCH005
pass # TC005
return


class Test:
if TYPE_CHECKING:
pass # TCH005
pass # TC005
x = 2


Expand All @@ -42,7 +42,7 @@ class Test:
from typing_extensions import TYPE_CHECKING

if TYPE_CHECKING:
pass # TCH005
pass # TC005

# https://github.com/astral-sh/ruff/issues/11368
if TYPE_CHECKING:
Expand Down
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 # TC010
x: ("int" | str) | "bool" # TC010


def func():
x: "int" | str # OK


z: list[str, str | "int"] = [] # TC010

type A = Value["int" | str] # OK

OldS = TypeVar('OldS', int | 'str', str) # TC010
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import TypeVar


x: "int" | str # TC010
x: ("int" | str) | "bool" # TC010


def func():
x: "int" | str # OK


z: list[str, str | "int"] = [] # TC010

type A = Value["int" | str] # OK

OldS = TypeVar('OldS', int | 'str', str) # TC010

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from pydantic import BaseModel

if TYPE_CHECKING:
import datetime # TCH004
from array import array # TCH004
import datetime # TC004
from array import array # TC004

import pandas # TCH004
import pandas # TC004
import pyproj


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import geopandas as gpd # TCH002
import geopandas as gpd # TC002
import pydantic
import pyproj # TCH002
import pyproj # TC002
from pydantic import BaseModel

import numpy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datetime
import pathlib
from uuid import UUID # TCH003
from uuid import UUID # TC003

import pydantic
from pydantic import BaseModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import numpy

if TYPE_CHECKING:
import datetime # TCH004
from array import array # TCH004
import datetime # TC004
from array import array # TC004

import pandas # TCH004
import pandas # TC004
import pyproj


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pyproj
from attrs import frozen

import numpy # TCH002
import numpy # TC002


@attrs.define(auto_attribs=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
from array import array
from dataclasses import dataclass
from uuid import UUID # TCH003
from uuid import UUID # TC003
from collections.abc import Sequence
from pydantic import validate_call

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub enum Linter {
#[prefix = "TID"]
Flake8TidyImports,
/// [flake8-type-checking](https://pypi.org/project/flake8-type-checking/)
#[prefix = "TCH"]
#[prefix = "TC"]
Flake8TypeChecking,
/// [flake8-gettext](https://pypi.org/project/flake8-gettext/)
#[prefix = "INT"]
Expand Down
14 changes: 11 additions & 3 deletions crates/ruff_linter/src/rule_redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ static REDIRECTS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(
("PDV90", "PD90"),
("PDV901", "PD901"),
// TODO(charlie): Remove by 2023-04-01.
("TYP", "TCH"),
("TYP001", "TCH001"),
("TYP", "TC"),
("TYP001", "TC001"),
// TODO(charlie): Remove by 2023-06-01.
("RUF004", "B026"),
("PIE802", "C419"),
Expand All @@ -98,7 +98,6 @@ static REDIRECTS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(
("T003", "FIX003"),
("T004", "FIX004"),
("RUF011", "B035"),
("TCH006", "TCH010"),
("TRY200", "B904"),
("PGH001", "S307"),
("PGH002", "G010"),
Expand Down Expand Up @@ -126,5 +125,14 @@ static REDIRECTS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(
("RUF025", "C420"),
// See: https://github.com/astral-sh/ruff/issues/13492
("TRY302", "TRY203"),
// TCH renamed to TC to harmonize with flake8 plugin
("TCH", "TC"),
("TCH001", "TC001"),
("TCH002", "TC002"),
("TCH003", "TC003"),
("TCH004", "TC004"),
("TCH005", "TC005"),
("TCH006", "TC010"),
("TCH010", "TC010"),
])
});
46 changes: 23 additions & 23 deletions crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,37 @@ mod tests {
use crate::test::{test_path, test_snippet};
use crate::{assert_messages, settings};

#[test_case(Rule::EmptyTypeCheckingBlock, Path::new("TCH005.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_1.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_10.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_11.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_12.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_13.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_14.pyi"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_15.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_16.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_17.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_2.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_3.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_4.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_5.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_6.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_7.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_8.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_9.py"))]
#[test_case(Rule::EmptyTypeCheckingBlock, Path::new("TC005.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_1.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_10.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_11.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_12.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_13.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_14.pyi"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_15.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_16.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_17.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_2.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_3.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_4.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_5.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_6.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_7.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_8.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TC004_9.py"))]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("quote.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::RuntimeStringUnion, Path::new("TC010_1.py"))]
#[test_case(Rule::RuntimeStringUnion, Path::new("TC010_2.py"))]
#[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TC001.py"))]
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TC003.py"))]
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("init_var.py"))]
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("kw_only.py"))]
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("snapshot.py"))]
#[test_case(
Rule::TypingOnlyStandardLibraryImport,
Path::new("singledispatchmethod.py")
)]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TCH002.py"))]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TC002.py"))]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("quote.py"))]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("singledispatch.py"))]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("strict.py"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl AlwaysFixableViolation for EmptyTypeCheckingBlock {
}
}

/// TCH005
/// TC005
pub(crate) fn empty_type_checking_block(checker: &mut Checker, stmt: &ast::StmtIf) {
if !typing::is_type_checking_block(stmt, checker.semantic()) {
return;
Expand Down
Loading
Loading