@@ -52,16 +52,13 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
52
52
// Identify any valid runtime imports. If a module is imported at runtime, and
53
53
// used at runtime, then by default, we avoid flagging any other
54
54
// imports from that model as typing-only.
55
- // FIXME: This does not seem quite right, if only TC004 is enabled
56
- // then we don't need to collect the runtime imports
57
- let enforce_typing_imports = !checker. source_type . is_stub ( )
55
+ let enforce_typing_only_imports = !checker. source_type . is_stub ( )
58
56
&& checker. any_enabled ( & [
59
- Rule :: RuntimeImportInTypeCheckingBlock ,
60
57
Rule :: TypingOnlyFirstPartyImport ,
61
58
Rule :: TypingOnlyStandardLibraryImport ,
62
59
Rule :: TypingOnlyThirdPartyImport ,
63
60
] ) ;
64
- let runtime_imports: Vec < Vec < & Binding > > = if enforce_typing_imports {
61
+ let runtime_imports: Vec < Vec < & Binding > > = if enforce_typing_only_imports {
65
62
checker
66
63
. semantic
67
64
. scopes
@@ -377,9 +374,16 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
377
374
}
378
375
379
376
if matches ! ( scope. kind, ScopeKind :: Function ( _) | ScopeKind :: Module ) {
380
- // FIXME: This does not seem quite right, if only TC004 is enabled
381
- // then we don't need to collect the runtime imports
382
- if enforce_typing_imports {
377
+ if !checker. source_type . is_stub ( )
378
+ && checker. enabled ( Rule :: RuntimeImportInTypeCheckingBlock )
379
+ {
380
+ flake8_type_checking:: rules:: runtime_import_in_type_checking_block (
381
+ checker,
382
+ scope,
383
+ & mut diagnostics,
384
+ ) ;
385
+ }
386
+ if enforce_typing_only_imports {
383
387
let runtime_imports: Vec < & Binding > = checker
384
388
. semantic
385
389
. scopes
@@ -388,26 +392,12 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
388
392
. copied ( )
389
393
. collect ( ) ;
390
394
391
- if checker. enabled ( Rule :: RuntimeImportInTypeCheckingBlock ) {
392
- flake8_type_checking:: rules:: runtime_import_in_type_checking_block (
393
- checker,
394
- scope,
395
- & mut diagnostics,
396
- ) ;
397
- }
398
-
399
- if checker. any_enabled ( & [
400
- Rule :: TypingOnlyFirstPartyImport ,
401
- Rule :: TypingOnlyStandardLibraryImport ,
402
- Rule :: TypingOnlyThirdPartyImport ,
403
- ] ) {
404
- flake8_type_checking:: rules:: typing_only_runtime_import (
405
- checker,
406
- scope,
407
- & runtime_imports,
408
- & mut diagnostics,
409
- ) ;
410
- }
395
+ flake8_type_checking:: rules:: typing_only_runtime_import (
396
+ checker,
397
+ scope,
398
+ & runtime_imports,
399
+ & mut diagnostics,
400
+ ) ;
411
401
}
412
402
413
403
if checker. enabled ( Rule :: UnusedImport ) {
0 commit comments