Skip to content

Commit c4dbd36

Browse files
committed
[ty] Improve isinstance() reachability analysis for generic types
1 parent 2ab1502 commit c4dbd36

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/ty_python_semantic/src/types/function.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ use crate::types::narrow::ClassInfoConstraintFunction;
7676
use crate::types::signatures::{CallableSignature, Signature};
7777
use crate::types::visitor::any_over_type;
7878
use crate::types::{
79-
BoundMethodType, CallableType, ClassLiteral, ClassType, DeprecatedInstance, DynamicType,
80-
KnownClass, Truthiness, Type, TypeMapping, TypeRelation, TypeTransformer, TypeVarInstance,
81-
UnionBuilder, all_members, walk_type_mapping,
79+
BoundMethodType, CallableType, ClassBase, ClassLiteral, ClassType, DeprecatedInstance,
80+
DynamicType, KnownClass, Truthiness, Type, TypeMapping, TypeRelation, TypeTransformer,
81+
TypeVarInstance, UnionBuilder, all_members, walk_type_mapping,
8282
};
8383
use crate::{Db, FxOrderSet, ModuleName, resolve_module};
8484

@@ -901,7 +901,12 @@ fn is_instance_truthiness<'db>(
901901
if let Type::NominalInstance(instance) = ty {
902902
if instance
903903
.class
904-
.is_subclass_of(db, ClassType::NonGeneric(class))
904+
.iter_mro(db)
905+
.filter_map(ClassBase::into_class)
906+
.any(|c| match c {
907+
ClassType::Generic(c) => c.origin(db) == class,
908+
ClassType::NonGeneric(c) => c == class,
909+
})
905910
{
906911
return true;
907912
}

0 commit comments

Comments
 (0)