mirror of https://github.com/astral-sh/ruff
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.)
This commit is contained in:
parent
86b6a3e1ad
commit
45318d08b7
|
|
@ -4860,26 +4860,22 @@ impl<'a> Checker<'a> {
|
||||||
])
|
])
|
||||||
};
|
};
|
||||||
let runtime_imports: Vec<Vec<&Binding>> = if enforce_typing_imports {
|
let runtime_imports: Vec<Vec<&Binding>> = if enforce_typing_imports {
|
||||||
if self.settings.flake8_type_checking.strict {
|
self.semantic
|
||||||
vec![]
|
.scopes
|
||||||
} else {
|
.iter()
|
||||||
self.semantic
|
.map(|scope| {
|
||||||
.scopes
|
scope
|
||||||
.iter()
|
.binding_ids()
|
||||||
.map(|scope| {
|
.map(|binding_id| self.semantic.binding(binding_id))
|
||||||
scope
|
.filter(|binding| {
|
||||||
.binding_ids()
|
flake8_type_checking::helpers::is_valid_runtime_import(
|
||||||
.map(|binding_id| self.semantic.binding(binding_id))
|
binding,
|
||||||
.filter(|binding| {
|
&self.semantic,
|
||||||
flake8_type_checking::helpers::is_valid_runtime_import(
|
)
|
||||||
binding,
|
})
|
||||||
&self.semantic,
|
.collect()
|
||||||
)
|
})
|
||||||
})
|
.collect::<Vec<_>>()
|
||||||
.collect()
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
|
@ -5070,17 +5066,13 @@ impl<'a> Checker<'a> {
|
||||||
ScopeKind::Function(_) | ScopeKind::AsyncFunction(_) | ScopeKind::Module
|
ScopeKind::Function(_) | ScopeKind::AsyncFunction(_) | ScopeKind::Module
|
||||||
) {
|
) {
|
||||||
if enforce_typing_imports {
|
if enforce_typing_imports {
|
||||||
let runtime_imports: Vec<&Binding> =
|
let runtime_imports: Vec<&Binding> = self
|
||||||
if self.settings.flake8_type_checking.strict {
|
.semantic
|
||||||
vec![]
|
.scopes
|
||||||
} else {
|
.ancestor_ids(scope_id)
|
||||||
self.semantic
|
.flat_map(|scope_id| runtime_imports[scope_id.as_usize()].iter())
|
||||||
.scopes
|
.copied()
|
||||||
.ancestor_ids(scope_id)
|
.collect();
|
||||||
.flat_map(|scope_id| runtime_imports[scope_id.as_usize()].iter())
|
|
||||||
.copied()
|
|
||||||
.collect()
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.enabled(Rule::RuntimeImportInTypeCheckingBlock) {
|
if self.enabled(Rule::RuntimeImportInTypeCheckingBlock) {
|
||||||
flake8_type_checking::rules::runtime_import_in_type_checking_block(
|
flake8_type_checking::rules::runtime_import_in_type_checking_block(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue