mirror of https://github.com/astral-sh/ruff
Actually, rename TYP rules to TCH (#2176)
This commit is contained in:
parent
6ede030700
commit
23525a8ea0
14
README.md
14
README.md
|
|
@ -144,7 +144,7 @@ developer of [Zulip](https://github.com/zulip/zulip):
|
||||||
1. [flake8-commas (COM)](#flake8-commas-com)
|
1. [flake8-commas (COM)](#flake8-commas-com)
|
||||||
1. [flake8-no-pep420 (INP)](#flake8-no-pep420-inp)
|
1. [flake8-no-pep420 (INP)](#flake8-no-pep420-inp)
|
||||||
1. [flake8-executable (EXE)](#flake8-executable-exe)
|
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. [tryceratops (TRY)](#tryceratops-try)
|
||||||
1. [flake8-use-pathlib (PTH)](#flake8-use-pathlib-pth)
|
1. [flake8-use-pathlib (PTH)](#flake8-use-pathlib-pth)
|
||||||
1. [Ruff-specific rules (RUF)](#ruff-specific-rules-ruf)<!-- End auto-generated table of contents. -->
|
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 | 🛠 |
|
| EXE004 | shebang-whitespace | Avoid whitespace before shebang | 🛠 |
|
||||||
| EXE005 | shebang-newline | Shebang should be at the beginning of the file | |
|
| 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.
|
For more, see [flake8-type-checking](https://pypi.org/project/flake8-type-checking/) on PyPI.
|
||||||
|
|
||||||
| Code | Name | Message | Fix |
|
| Code | Name | Message | Fix |
|
||||||
| ---- | ---- | ------- | --- |
|
| ---- | ---- | ------- | --- |
|
||||||
| TYC001 | typing-only-first-party-import | Move application import `{}` into a type-checking block | |
|
| TCH001 | 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 | |
|
| TCH002 | 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 | |
|
| TCH003 | 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. | |
|
| TCH004 | 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 | |
|
| TCH005 | empty-type-checking-block | Found empty type-checking block | |
|
||||||
|
|
||||||
### tryceratops (TRY)
|
### tryceratops (TRY)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Tests to determine first-party import classification.
|
"""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`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2,43 +2,43 @@
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
import pandas as pd # TYC002
|
import pandas as pd # TCH002
|
||||||
|
|
||||||
x: pd.DataFrame
|
x: pd.DataFrame
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
from pandas import DataFrame # TYC002
|
from pandas import DataFrame # TCH002
|
||||||
|
|
||||||
x: DataFrame
|
x: DataFrame
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
from pandas import DataFrame as df # TYC002
|
from pandas import DataFrame as df # TCH002
|
||||||
|
|
||||||
x: df
|
x: df
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
import pandas as pd # TYC002
|
import pandas as pd # TCH002
|
||||||
|
|
||||||
x: pd.DataFrame = 1
|
x: pd.DataFrame = 1
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
from pandas import DataFrame # TYC002
|
from pandas import DataFrame # TCH002
|
||||||
|
|
||||||
x: DataFrame = 2
|
x: DataFrame = 2
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
from pandas import DataFrame as df # TYC002
|
from pandas import DataFrame as df # TCH002
|
||||||
|
|
||||||
x: df = 3
|
x: df = 3
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
import pandas as pd # TYC002
|
import pandas as pd # TCH002
|
||||||
|
|
||||||
x: "pd.DataFrame" = 1
|
x: "pd.DataFrame" = 1
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ def f():
|
||||||
def f():
|
def f():
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
x = dict["pd.DataFrame", "pd.DataFrame"] # TYC002
|
x = dict["pd.DataFrame", "pd.DataFrame"] # TCH002
|
||||||
|
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Tests to determine standard library import classification.
|
"""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`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
pass # TYC005
|
pass # TCH005
|
||||||
|
|
||||||
|
|
||||||
def example():
|
def example():
|
||||||
|
|
@ -1760,6 +1760,14 @@
|
||||||
"T20",
|
"T20",
|
||||||
"T201",
|
"T201",
|
||||||
"T203",
|
"T203",
|
||||||
|
"TCH",
|
||||||
|
"TCH0",
|
||||||
|
"TCH00",
|
||||||
|
"TCH001",
|
||||||
|
"TCH002",
|
||||||
|
"TCH003",
|
||||||
|
"TCH004",
|
||||||
|
"TCH005",
|
||||||
"TID",
|
"TID",
|
||||||
"TID2",
|
"TID2",
|
||||||
"TID25",
|
"TID25",
|
||||||
|
|
@ -1777,14 +1785,6 @@
|
||||||
"TRY30",
|
"TRY30",
|
||||||
"TRY300",
|
"TRY300",
|
||||||
"TRY301",
|
"TRY301",
|
||||||
"TYC",
|
|
||||||
"TYC0",
|
|
||||||
"TYC00",
|
|
||||||
"TYC001",
|
|
||||||
"TYC002",
|
|
||||||
"TYC003",
|
|
||||||
"TYC004",
|
|
||||||
"TYC005",
|
|
||||||
"UP",
|
"UP",
|
||||||
"UP0",
|
"UP0",
|
||||||
"UP00",
|
"UP00",
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ impl Plugin {
|
||||||
Plugin::Flake8Return => RuleCodePrefix::RET.into(),
|
Plugin::Flake8Return => RuleCodePrefix::RET.into(),
|
||||||
Plugin::Flake8Simplify => RuleCodePrefix::SIM.into(),
|
Plugin::Flake8Simplify => RuleCodePrefix::SIM.into(),
|
||||||
Plugin::Flake8TidyImports => RuleCodePrefix::TID.into(),
|
Plugin::Flake8TidyImports => RuleCodePrefix::TID.into(),
|
||||||
Plugin::Flake8TypeChecking => RuleCodePrefix::TYC.into(),
|
Plugin::Flake8TypeChecking => RuleCodePrefix::TCH.into(),
|
||||||
Plugin::Flake8UnusedArguments => RuleCodePrefix::ARG.into(),
|
Plugin::Flake8UnusedArguments => RuleCodePrefix::ARG.into(),
|
||||||
Plugin::Flake8UsePathlib => RuleCodePrefix::PTH.into(),
|
Plugin::Flake8UsePathlib => RuleCodePrefix::PTH.into(),
|
||||||
Plugin::McCabe => RuleCodePrefix::C9.into(),
|
Plugin::McCabe => RuleCodePrefix::C9.into(),
|
||||||
|
|
|
||||||
|
|
@ -429,11 +429,11 @@ ruff_macros::define_rule_mapping!(
|
||||||
EXE004 => rules::flake8_executable::rules::ShebangWhitespace,
|
EXE004 => rules::flake8_executable::rules::ShebangWhitespace,
|
||||||
EXE005 => rules::flake8_executable::rules::ShebangNewline,
|
EXE005 => rules::flake8_executable::rules::ShebangNewline,
|
||||||
// flake8-type-checking
|
// flake8-type-checking
|
||||||
TYC001 => rules::flake8_type_checking::rules::TypingOnlyFirstPartyImport,
|
TCH001 => rules::flake8_type_checking::rules::TypingOnlyFirstPartyImport,
|
||||||
TYC002 => rules::flake8_type_checking::rules::TypingOnlyThirdPartyImport,
|
TCH002 => rules::flake8_type_checking::rules::TypingOnlyThirdPartyImport,
|
||||||
TYC003 => rules::flake8_type_checking::rules::TypingOnlyStandardLibraryImport,
|
TCH003 => rules::flake8_type_checking::rules::TypingOnlyStandardLibraryImport,
|
||||||
TYC004 => rules::flake8_type_checking::rules::RuntimeImportInTypeCheckingBlock,
|
TCH004 => rules::flake8_type_checking::rules::RuntimeImportInTypeCheckingBlock,
|
||||||
TYC005 => rules::flake8_type_checking::rules::EmptyTypeCheckingBlock,
|
TCH005 => rules::flake8_type_checking::rules::EmptyTypeCheckingBlock,
|
||||||
// tryceratops
|
// tryceratops
|
||||||
TRY004 => rules::tryceratops::rules::PreferTypeError,
|
TRY004 => rules::tryceratops::rules::PreferTypeError,
|
||||||
TRY200 => rules::tryceratops::rules::ReraiseNoCause,
|
TRY200 => rules::tryceratops::rules::ReraiseNoCause,
|
||||||
|
|
@ -584,7 +584,7 @@ pub enum Linter {
|
||||||
#[prefix = "EXE"]
|
#[prefix = "EXE"]
|
||||||
Flake8Executable,
|
Flake8Executable,
|
||||||
/// [flake8-type-checking](https://pypi.org/project/flake8-type-checking/)
|
/// [flake8-type-checking](https://pypi.org/project/flake8-type-checking/)
|
||||||
#[prefix = "TYC"]
|
#[prefix = "TCH"]
|
||||||
Flake8TypeChecking,
|
Flake8TypeChecking,
|
||||||
/// [tryceratops](https://pypi.org/project/tryceratops/1.1.0/)
|
/// [tryceratops](https://pypi.org/project/tryceratops/1.1.0/)
|
||||||
#[prefix = "TRY"]
|
#[prefix = "TRY"]
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
|
||||||
("PDV90", "PD90"),
|
("PDV90", "PD90"),
|
||||||
("PDV901", "PD901"),
|
("PDV901", "PD901"),
|
||||||
// TODO(charlie): Remove by 2023-04-01.
|
// TODO(charlie): Remove by 2023-04-01.
|
||||||
("TYP", "TYC"),
|
("TYP", "TCH"),
|
||||||
("TYP001", "TYC001"),
|
("TYP001", "TCH001"),
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,18 @@ mod tests {
|
||||||
use crate::registry::Rule;
|
use crate::registry::Rule;
|
||||||
use crate::settings;
|
use crate::settings;
|
||||||
|
|
||||||
#[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TYC001.py"); "TYC001")]
|
#[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TCH001.py"); "TCH001")]
|
||||||
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TYC002.py"); "TYC002")]
|
#[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TCH002.py"); "TCH002")]
|
||||||
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TYC003.py"); "TYC003")]
|
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("TCH003.py"); "TCH003")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_1.py"); "TYC004_1")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_1.py"); "TCH004_1")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_2.py"); "TYC004_2")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_2.py"); "TCH004_2")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_3.py"); "TYC004_3")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_3.py"); "TCH004_3")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_4.py"); "TYC004_4")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_4.py"); "TCH004_4")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_5.py"); "TYC004_5")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_5.py"); "TCH004_5")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_6.py"); "TYC004_6")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_6.py"); "TCH004_6")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_7.py"); "TYC004_7")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_7.py"); "TCH004_7")]
|
||||||
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TYC004_8.py"); "TYC004_8")]
|
#[test_case(Rule::RuntimeImportInTypeCheckingBlock, Path::new("TCH004_8.py"); "TCH004_8")]
|
||||||
#[test_case(Rule::EmptyTypeCheckingBlock, Path::new("TYC005.py"); "TYC005")]
|
#[test_case(Rule::EmptyTypeCheckingBlock, Path::new("TCH005.py"); "TCH005")]
|
||||||
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
|
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||||
let diagnostics = test_path(
|
let diagnostics = test_path(
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ impl Violation for EmptyTypeCheckingBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TYC005
|
/// TCH005
|
||||||
pub fn empty_type_checking_block(checker: &mut Checker, test: &Expr, body: &[Stmt]) {
|
pub fn empty_type_checking_block(checker: &mut Checker, test: &Expr, body: &[Stmt]) {
|
||||||
if checker.resolve_call_path(test).map_or(false, |call_path| {
|
if checker.resolve_call_path(test).map_or(false, |call_path| {
|
||||||
call_path.as_slice() == ["typing", "TYPE_CHECKING"]
|
call_path.as_slice() == ["typing", "TYPE_CHECKING"]
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ impl Violation for RuntimeImportInTypeCheckingBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TYC004
|
/// TCH004
|
||||||
pub fn runtime_import_in_type_checking_block(
|
pub fn runtime_import_in_type_checking_block(
|
||||||
binding: &Binding,
|
binding: &Binding,
|
||||||
blocks: &[&Stmt],
|
blocks: &[&Stmt],
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ impl Violation for TypingOnlyStandardLibraryImport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TYC001
|
/// TCH001
|
||||||
pub fn typing_only_runtime_import(
|
pub fn typing_only_runtime_import(
|
||||||
binding: &Binding,
|
binding: &Binding,
|
||||||
blocks: &[&Stmt],
|
blocks: &[&Stmt],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue