From bed788383943a69e5bdc95b0f1d33ee07e8fda4f Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 15 Jul 2023 16:57:29 -0400 Subject: [PATCH] Gate `runtime-import-in-type-checking-block` (`TCH004`) behind enabled flag (#5789) Closes #5787. --- crates/ruff/src/checkers/ast/mod.rs | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index e6b64dc1cf8b44..902ce741389433 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -5005,18 +5005,26 @@ impl<'a> Checker<'a> { .collect() }; - flake8_type_checking::rules::runtime_import_in_type_checking_block( - self, - scope, - &mut diagnostics, - ); + if self.enabled(Rule::RuntimeImportInTypeCheckingBlock) { + flake8_type_checking::rules::runtime_import_in_type_checking_block( + self, + scope, + &mut diagnostics, + ); + } - flake8_type_checking::rules::typing_only_runtime_import( - self, - scope, - &runtime_imports, - &mut diagnostics, - ); + if self.any_enabled(&[ + Rule::TypingOnlyFirstPartyImport, + Rule::TypingOnlyThirdPartyImport, + Rule::TypingOnlyStandardLibraryImport, + ]) { + flake8_type_checking::rules::typing_only_runtime_import( + self, + scope, + &runtime_imports, + &mut diagnostics, + ); + } } if self.enabled(Rule::UnusedImport) {