Skip to content

Commit

Permalink
Respect subscripted base classes in type-checking rules (#7954)
Browse files Browse the repository at this point in the history
Closes #7945.
  • Loading branch information
charliermarsh authored Oct 13, 2023
1 parent ddffadb commit bd06cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ class C:

class D(C):
x: UUID


import collections


class E(BaseModel[int]):
x: collections.Awaitable
14 changes: 8 additions & 6 deletions crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ruff_python_ast::call_path::from_qualified_name;
use ruff_python_ast::helpers::map_callable;
use ruff_python_ast::helpers::{map_callable, map_subscript};
use ruff_python_semantic::{Binding, BindingKind, ScopeKind, SemanticModel};

pub(crate) fn is_valid_runtime_import(binding: &Binding, semantic: &SemanticModel) -> bool {
Expand Down Expand Up @@ -40,11 +40,13 @@ fn runtime_evaluated_base_class(base_classes: &[String], semantic: &SemanticMode
};

class_def.bases().iter().any(|base| {
semantic.resolve_call_path(base).is_some_and(|call_path| {
base_classes
.iter()
.any(|base_class| from_qualified_name(base_class) == call_path)
})
semantic
.resolve_call_path(map_subscript(base))
.is_some_and(|call_path| {
base_classes
.iter()
.any(|base_class| from_qualified_name(base_class) == call_path)
})
})
}

Expand Down

0 comments on commit bd06cbe

Please sign in to comment.