Rename TYP rules to TYC (#2175)

This commit is contained in:
Charlie Marsh
2023-01-25 16:26:22 -05:00
committed by GitHub
parent d5dff11d4b
commit 35cf9e242e
34 changed files with 52 additions and 49 deletions

View File

@@ -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 (TYP)](#flake8-type-checking-typ)
1. [flake8-type-checking (TYC)](#flake8-type-checking-tyc)
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. -->
@@ -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 (TYP)
### flake8-type-checking (TYC)
For more, see [flake8-type-checking](https://pypi.org/project/flake8-type-checking/) on PyPI.
| Code | Name | Message | Fix |
| ---- | ---- | ------- | --- |
| TYP001 | typing-only-first-party-import | Move application import `{}` into a type-checking block | |
| TYP002 | typing-only-third-party-import | Move third-party import `{}` into a type-checking block | |
| TYP003 | typing-only-standard-library-import | Move standard library import `{}` into a type-checking block | |
| TYP004 | runtime-import-in-type-checking-block | Move import `{}` out of type-checking block. Import is used for more than type hinting. | |
| TYP005 | empty-type-checking-block | Found empty type-checking block | |
| 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 | |
### tryceratops (TRY)

View File

@@ -1,6 +1,6 @@
"""Tests to determine first-party import classification.
For typing-only import detection tests, see `TYP002.py`.
For typing-only import detection tests, see `TYC002.py`.
"""

View File

@@ -2,43 +2,43 @@
def f():
import pandas as pd # TYP002
import pandas as pd # TYC002
x: pd.DataFrame
def f():
from pandas import DataFrame # TYP002
from pandas import DataFrame # TYC002
x: DataFrame
def f():
from pandas import DataFrame as df # TYP002
from pandas import DataFrame as df # TYC002
x: df
def f():
import pandas as pd # TYP002
import pandas as pd # TYC002
x: pd.DataFrame = 1
def f():
from pandas import DataFrame # TYP002
from pandas import DataFrame # TYC002
x: DataFrame = 2
def f():
from pandas import DataFrame as df # TYP002
from pandas import DataFrame as df # TYC002
x: df = 3
def f():
import pandas as pd # TYP002
import pandas as pd # TYC002
x: "pd.DataFrame" = 1
@@ -46,7 +46,7 @@ def f():
def f():
import pandas as pd
x = dict["pd.DataFrame", "pd.DataFrame"] # TYP002
x = dict["pd.DataFrame", "pd.DataFrame"] # TYC002
def f():

View File

@@ -1,6 +1,6 @@
"""Tests to determine standard library import classification.
For typing-only import detection tests, see `TYP002.py`.
For typing-only import detection tests, see `TYC002.py`.
"""

View File

@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING, List
if TYPE_CHECKING:
pass # TYP005
pass # TYC005
def example():

View File

@@ -1777,14 +1777,14 @@
"TRY30",
"TRY300",
"TRY301",
"TYP",
"TYP0",
"TYP00",
"TYP001",
"TYP002",
"TYP003",
"TYP004",
"TYP005",
"TYC",
"TYC0",
"TYC00",
"TYC001",
"TYC002",
"TYC003",
"TYC004",
"TYC005",
"UP",
"UP0",
"UP00",

View File

@@ -160,7 +160,7 @@ impl Plugin {
Plugin::Flake8Return => RuleCodePrefix::RET.into(),
Plugin::Flake8Simplify => RuleCodePrefix::SIM.into(),
Plugin::Flake8TidyImports => RuleCodePrefix::TID.into(),
Plugin::Flake8TypeChecking => RuleCodePrefix::TYP.into(),
Plugin::Flake8TypeChecking => RuleCodePrefix::TYC.into(),
Plugin::Flake8UnusedArguments => RuleCodePrefix::ARG.into(),
Plugin::Flake8UsePathlib => RuleCodePrefix::PTH.into(),
Plugin::McCabe => RuleCodePrefix::C9.into(),

View File

@@ -429,11 +429,11 @@ ruff_macros::define_rule_mapping!(
EXE004 => rules::flake8_executable::rules::ShebangWhitespace,
EXE005 => rules::flake8_executable::rules::ShebangNewline,
// flake8-type-checking
TYP001 => rules::flake8_type_checking::rules::TypingOnlyFirstPartyImport,
TYP002 => rules::flake8_type_checking::rules::TypingOnlyThirdPartyImport,
TYP003 => rules::flake8_type_checking::rules::TypingOnlyStandardLibraryImport,
TYP004 => rules::flake8_type_checking::rules::RuntimeImportInTypeCheckingBlock,
TYP005 => rules::flake8_type_checking::rules::EmptyTypeCheckingBlock,
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,
// tryceratops
TRY004 => rules::tryceratops::rules::PreferTypeError,
TRY200 => rules::tryceratops::rules::ReraiseNoCause,
@@ -584,7 +584,7 @@ pub enum Linter {
#[prefix = "EXE"]
Flake8Executable,
/// [flake8-type-checking](https://pypi.org/project/flake8-type-checking/)
#[prefix = "TYP"]
#[prefix = "TYC"]
Flake8TypeChecking,
/// [tryceratops](https://pypi.org/project/tryceratops/1.1.0/)
#[prefix = "TRY"]

View File

@@ -81,5 +81,8 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
("PDV9", "PD9"),
("PDV90", "PD90"),
("PDV901", "PD901"),
// TODO(charlie): Remove by 2023-04-01.
("TYP", "TYC"),
("TYP001", "TYC001"),
])
});

View File

@@ -14,18 +14,18 @@ mod tests {
use crate::registry::Rule;
use crate::settings;
#[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TYP001.py"); "TYP001")]
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TYP002.py"); "TYP002")]
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TYP003.py"); "TYP003")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_1.py"); "TYP004_1")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_2.py"); "TYP004_2")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_3.py"); "TYP004_3")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_4.py"); "TYP004_4")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_5.py"); "TYP004_5")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_6.py"); "TYP004_6")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_7.py"); "TYP004_7")]
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYP004_8.py"); "TYP004_8")]
#[test_case(Rule::EmptyTypeCheckingBlock, Path::new("TYP005.py"); "TYP005")]
#[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")]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
let diagnostics = test_path(

View File

@@ -17,7 +17,7 @@ impl Violation for EmptyTypeCheckingBlock {
}
}
/// TYP005
/// TYC005
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"]

View File

@@ -22,7 +22,7 @@ impl Violation for RuntimeImportInTypeCheckingBlock {
}
}
/// TYP004
/// TYC004
pub fn runtime_import_in_type_checking_block(
binding: &Binding,
blocks: &[&Stmt],

View File

@@ -55,7 +55,7 @@ impl Violation for TypingOnlyStandardLibraryImport {
}
}
/// TYP001
/// TYC001
pub fn typing_only_runtime_import(
binding: &Binding,
blocks: &[&Stmt],

View File

@@ -358,7 +358,7 @@ fn resolve_codes<'a>(specs: impl IntoIterator<Item = RuleCodeSpec<'a>>) -> FxHas
for (from, target) in redirects {
// TODO(martin): This belongs into the ruff_cli crate.
crate::warn_user!("`{from}` has been remapped to `{}`", target.as_ref());
crate::warn_user!("`{from}` has been remapped to `{}`.", target.as_ref());
}
rules