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

Actually, rename TYP rules to TCH #2176

Merged
merged 1 commit into from
Jan 25, 2023
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
Actually, rename TYP rules to TCH
  • Loading branch information
charliermarsh committed Jan 25, 2023
commit 63d27eea850083e90ed7378d63d8aae9e3b26fdc
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ developer of [Zulip](https://github.com/zulip/zulip):
1. [flake8-commas (COM)](#flake8-commas-com)
1. [flake8-no-pep420 (INP)](#flake8-no-pep420-inp)
1. [flake8-executable (EXE)](#flake8-executable-exe)
1. [flake8-type-checking (TYC)](#flake8-type-checking-tyc)
1. [flake8-type-checking (TCH)](#flake8-type-checking-tch)
1. [tryceratops (TRY)](#tryceratops-try)
1. [flake8-use-pathlib (PTH)](#flake8-use-pathlib-pth)
1. [Ruff-specific rules (RUF)](#ruff-specific-rules-ruf)<!-- End auto-generated table of contents. -->
Expand Down Expand Up @@ -1197,17 +1197,17 @@ For more, see [flake8-executable](https://pypi.org/project/flake8-executable/) o
| EXE004 | shebang-whitespace | Avoid whitespace before shebang | 🛠 |
| EXE005 | shebang-newline | Shebang should be at the beginning of the file | |

### flake8-type-checking (TYC)
### flake8-type-checking (TCH)

For more, see [flake8-type-checking](https://pypi.org/project/flake8-type-checking/) on PyPI.

| Code | Name | Message | Fix |
| ---- | ---- | ------- | --- |
| TYC001 | typing-only-first-party-import | Move application import `{}` into a type-checking block | |
| TYC002 | typing-only-third-party-import | Move third-party import `{}` into a type-checking block | |
| TYC003 | typing-only-standard-library-import | Move standard library import `{}` into a type-checking block | |
| TYC004 | runtime-import-in-type-checking-block | Move import `{}` out of type-checking block. Import is used for more than type hinting. | |
| TYC005 | empty-type-checking-block | Found empty type-checking block | |
| TCH001 | typing-only-first-party-import | Move application import `{}` into a type-checking block | |
| TCH002 | typing-only-third-party-import | Move third-party import `{}` into a type-checking block | |
| TCH003 | typing-only-standard-library-import | Move standard library import `{}` into a type-checking block | |
| TCH004 | runtime-import-in-type-checking-block | Move import `{}` out of type-checking block. Import is used for more than type hinting. | |
| TCH005 | empty-type-checking-block | Found empty type-checking block | |

### tryceratops (TRY)

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 `TYC002.py`.
For typing-only import detection tests, see `TCH002.py`.
"""


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


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

x: pd.DataFrame


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

x: DataFrame


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

x: df


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

x: pd.DataFrame = 1


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

x: DataFrame = 2


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

x: df = 3


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

x: "pd.DataFrame" = 1


def f():
import pandas as pd

x = dict["pd.DataFrame", "pd.DataFrame"] # TYC002
x = dict["pd.DataFrame", "pd.DataFrame"] # TCH002


def f():
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 `TYC002.py`.
For typing-only import detection tests, see `TCH002.py`.
"""


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

if TYPE_CHECKING:
pass # TYC005
pass # TCH005


def example():
Expand Down
16 changes: 8 additions & 8 deletions ruff.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,14 @@
"T20",
"T201",
"T203",
"TCH",
"TCH0",
"TCH00",
"TCH001",
"TCH002",
"TCH003",
"TCH004",
"TCH005",
"TID",
"TID2",
"TID25",
Expand All @@ -1777,14 +1785,6 @@
"TRY30",
"TRY300",
"TRY301",
"TYC",
"TYC0",
"TYC00",
"TYC001",
"TYC002",
"TYC003",
"TYC004",
"TYC005",
"UP",
"UP0",
"UP00",
Expand Down
2 changes: 1 addition & 1 deletion src/flake8_to_ruff/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Plugin {
Plugin::Flake8Return => RuleCodePrefix::RET.into(),
Plugin::Flake8Simplify => RuleCodePrefix::SIM.into(),
Plugin::Flake8TidyImports => RuleCodePrefix::TID.into(),
Plugin::Flake8TypeChecking => RuleCodePrefix::TYC.into(),
Plugin::Flake8TypeChecking => RuleCodePrefix::TCH.into(),
Plugin::Flake8UnusedArguments => RuleCodePrefix::ARG.into(),
Plugin::Flake8UsePathlib => RuleCodePrefix::PTH.into(),
Plugin::McCabe => RuleCodePrefix::C9.into(),
Expand Down
12 changes: 6 additions & 6 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,11 @@ ruff_macros::define_rule_mapping!(
EXE004 => rules::flake8_executable::rules::ShebangWhitespace,
EXE005 => rules::flake8_executable::rules::ShebangNewline,
// flake8-type-checking
TYC001 => rules::flake8_type_checking::rules::TypingOnlyFirstPartyImport,
TYC002 => rules::flake8_type_checking::rules::TypingOnlyThirdPartyImport,
TYC003 => rules::flake8_type_checking::rules::TypingOnlyStandardLibraryImport,
TYC004 => rules::flake8_type_checking::rules::RuntimeImportInTypeCheckingBlock,
TYC005 => rules::flake8_type_checking::rules::EmptyTypeCheckingBlock,
TCH001 => rules::flake8_type_checking::rules::TypingOnlyFirstPartyImport,
TCH002 => rules::flake8_type_checking::rules::TypingOnlyThirdPartyImport,
TCH003 => rules::flake8_type_checking::rules::TypingOnlyStandardLibraryImport,
TCH004 => rules::flake8_type_checking::rules::RuntimeImportInTypeCheckingBlock,
TCH005 => rules::flake8_type_checking::rules::EmptyTypeCheckingBlock,
// tryceratops
TRY004 => rules::tryceratops::rules::PreferTypeError,
TRY200 => rules::tryceratops::rules::ReraiseNoCause,
Expand Down Expand Up @@ -584,7 +584,7 @@ pub enum Linter {
#[prefix = "EXE"]
Flake8Executable,
/// [flake8-type-checking](https://pypi.org/project/flake8-type-checking/)
#[prefix = "TYC"]
#[prefix = "TCH"]
Flake8TypeChecking,
/// [tryceratops](https://pypi.org/project/tryceratops/1.1.0/)
#[prefix = "TRY"]
Expand Down
4 changes: 2 additions & 2 deletions src/rule_redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
("PDV90", "PD90"),
("PDV901", "PD901"),
// TODO(charlie): Remove by 2023-04-01.
("TYP", "TYC"),
("TYP001", "TYC001"),
("TYP", "TCH"),
("TYP001", "TCH001"),
])
});
24 changes: 12 additions & 12 deletions src/rules/flake8_type_checking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ mod tests {
use crate::registry::Rule;
use crate::settings;

#[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TYC001.py"); "TYC001")]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TYC002.py"); "TYC002")]
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TYC003.py"); "TYC003")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_1.py"); "TYC004_1")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_2.py"); "TYC004_2")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_3.py"); "TYC004_3")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_4.py"); "TYC004_4")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_5.py"); "TYC004_5")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_6.py"); "TYC004_6")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_7.py"); "TYC004_7")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_8.py"); "TYC004_8")]
#[test_case(Rule::EmptyTypeCheckingBlock, Path::new("TYC005.py"); "TYC005")]
#[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TCH001.py"); "TCH001")]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TCH002.py"); "TCH002")]
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TCH003.py"); "TCH003")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_1.py"); "TCH004_1")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_2.py"); "TCH004_2")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_3.py"); "TCH004_3")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_4.py"); "TCH004_4")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_5.py"); "TCH004_5")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_6.py"); "TCH004_6")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_7.py"); "TCH004_7")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_8.py"); "TCH004_8")]
#[test_case(Rule::EmptyTypeCheckingBlock, Path::new("TCH005.py"); "TCH005")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
let diagnostics = test_path(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Violation for EmptyTypeCheckingBlock {
}
}

/// TYC005
/// TCH005
pub fn empty_type_checking_block(checker: &mut Checker, test: &Expr, body: &[Stmt]) {
if checker.resolve_call_path(test).map_or(false, |call_path| {
call_path.as_slice() == ["typing", "TYPE_CHECKING"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Violation for RuntimeImportInTypeCheckingBlock {
}
}

/// TYC004
/// TCH004
pub fn runtime_import_in_type_checking_block(
binding: &Binding,
blocks: &[&Stmt],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Violation for TypingOnlyStandardLibraryImport {
}
}

/// TYC001
/// TCH001
pub fn typing_only_runtime_import(
binding: &Binding,
blocks: &[&Stmt],
Expand Down