From 45318d08b72dc27ec972c3e57764c40d9a6f3436 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 21 Jul 2023 23:53:33 -0400 Subject: [PATCH] Always compute runtime annotations for flake8-type-checking rules (#5967) ## Summary These are skipped as an optimization, but it feels kind of unnecessary and makes the code a bit more confusing than is worthwhile. (non-`strict` is also by far the more popular setting, and the default.) --- crates/ruff/src/checkers/ast/mod.rs | 54 ++++++++++++----------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index 8de2fae27f..a3c6aa040e 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -4860,26 +4860,22 @@ impl<'a> Checker<'a> { ]) }; let runtime_imports: Vec> = if enforce_typing_imports { - if self.settings.flake8_type_checking.strict { - vec![] - } else { - self.semantic - .scopes - .iter() - .map(|scope| { - scope - .binding_ids() - .map(|binding_id| self.semantic.binding(binding_id)) - .filter(|binding| { - flake8_type_checking::helpers::is_valid_runtime_import( - binding, - &self.semantic, - ) - }) - .collect() - }) - .collect::>() - } + self.semantic + .scopes + .iter() + .map(|scope| { + scope + .binding_ids() + .map(|binding_id| self.semantic.binding(binding_id)) + .filter(|binding| { + flake8_type_checking::helpers::is_valid_runtime_import( + binding, + &self.semantic, + ) + }) + .collect() + }) + .collect::>() } else { vec![] }; @@ -5070,17 +5066,13 @@ impl<'a> Checker<'a> { ScopeKind::Function(_) | ScopeKind::AsyncFunction(_) | ScopeKind::Module ) { if enforce_typing_imports { - let runtime_imports: Vec<&Binding> = - if self.settings.flake8_type_checking.strict { - vec![] - } else { - self.semantic - .scopes - .ancestor_ids(scope_id) - .flat_map(|scope_id| runtime_imports[scope_id.as_usize()].iter()) - .copied() - .collect() - }; + let runtime_imports: Vec<&Binding> = self + .semantic + .scopes + .ancestor_ids(scope_id) + .flat_map(|scope_id| runtime_imports[scope_id.as_usize()].iter()) + .copied() + .collect(); if self.enabled(Rule::RuntimeImportInTypeCheckingBlock) { flake8_type_checking::rules::runtime_import_in_type_checking_block(