mirror of https://github.com/astral-sh/ruff
is_subclass_of
This commit is contained in:
parent
5d9a8af775
commit
2be369f299
|
|
@ -1405,6 +1405,19 @@ impl<'db> ClassSingletonType<'db> {
|
||||||
Self::NewType(new_type) => new_type.dataclass_transformer_params(db),
|
Self::NewType(new_type) => new_type.dataclass_transformer_params(db),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn is_subclass_of(
|
||||||
|
self,
|
||||||
|
db: &'db dyn Db,
|
||||||
|
specialization: Option<Specialization<'db>>,
|
||||||
|
other: ClassType<'db>,
|
||||||
|
) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Literal(literal) => literal.is_subclass_of(db, specialization, other),
|
||||||
|
// A NewType can't be specialized.
|
||||||
|
Self::NewType(new_type) => new_type.is_subclass_of(db, other),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> From<ClassSingletonType<'db>> for Type<'db> {
|
impl<'db> From<ClassSingletonType<'db>> for Type<'db> {
|
||||||
|
|
@ -3249,7 +3262,7 @@ pub struct NewTypeClass<'db> {
|
||||||
#[returns(ref)]
|
#[returns(ref)]
|
||||||
name: Name,
|
name: Name,
|
||||||
|
|
||||||
parent: Box<ClassType<'db>>,
|
parent: ClassType<'db>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> NewTypeClass<'db> {
|
impl<'db> NewTypeClass<'db> {
|
||||||
|
|
@ -3332,6 +3345,15 @@ impl<'db> NewTypeClass<'db> {
|
||||||
) -> Option<DataclassTransformerParams> {
|
) -> Option<DataclassTransformerParams> {
|
||||||
self.parent(db).dataclass_transformer_params(db)
|
self.parent(db).dataclass_transformer_params(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn is_subclass_of(self, db: &'db dyn Db, other: ClassType<'db>) -> bool {
|
||||||
|
let parent = self.parent(db);
|
||||||
|
if parent == other {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
parent.is_subclass_of(db, other)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> get_size2::GetSize for NewTypeClass<'_> {}
|
impl<'db> get_size2::GetSize for NewTypeClass<'_> {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue