mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
[ty] Improve isinstance()
truthiness analysis for generic types (#19668)
This commit is contained in:
parent
d8151f0239
commit
18aae21b9a
3 changed files with 111 additions and 5 deletions
|
@ -76,9 +76,9 @@ use crate::types::narrow::ClassInfoConstraintFunction;
|
|||
use crate::types::signatures::{CallableSignature, Signature};
|
||||
use crate::types::visitor::any_over_type;
|
||||
use crate::types::{
|
||||
BoundMethodType, CallableType, ClassLiteral, ClassType, DeprecatedInstance, DynamicType,
|
||||
KnownClass, Truthiness, Type, TypeMapping, TypeRelation, TypeTransformer, TypeVarInstance,
|
||||
UnionBuilder, all_members, walk_type_mapping,
|
||||
BoundMethodType, CallableType, ClassBase, ClassLiteral, ClassType, DeprecatedInstance,
|
||||
DynamicType, KnownClass, Truthiness, Type, TypeMapping, TypeRelation, TypeTransformer,
|
||||
TypeVarInstance, UnionBuilder, all_members, walk_type_mapping,
|
||||
};
|
||||
use crate::{Db, FxOrderSet, ModuleName, resolve_module};
|
||||
|
||||
|
@ -901,7 +901,12 @@ fn is_instance_truthiness<'db>(
|
|||
if let Type::NominalInstance(instance) = ty {
|
||||
if instance
|
||||
.class
|
||||
.is_subclass_of(db, ClassType::NonGeneric(class))
|
||||
.iter_mro(db)
|
||||
.filter_map(ClassBase::into_class)
|
||||
.any(|c| match c {
|
||||
ClassType::Generic(c) => c.origin(db) == class,
|
||||
ClassType::NonGeneric(c) => c == class,
|
||||
})
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue