mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 16:10:17 +00:00
[red-knot] Inline SubclassOfType::as_instance_type_of_metaclass()
(#15556)
This commit is contained in:
parent
1ba8e61875
commit
4351d85d24
2 changed files with 7 additions and 10 deletions
|
@ -1311,7 +1311,13 @@ impl<'db> Type<'db> {
|
|||
|
||||
(Type::SubclassOf(subclass_of_ty), other)
|
||||
| (other, Type::SubclassOf(subclass_of_ty)) => {
|
||||
other.is_disjoint_from(db, subclass_of_ty.as_instance_type_of_metaclass(db))
|
||||
let metaclass_instance_ty = match subclass_of_ty.subclass_of() {
|
||||
// for `type[Any]`/`type[Unknown]`/`type[Todo]`, we know the type cannot be any larger than `type`,
|
||||
// so although the type is dynamic we can still determine disjointness in some situations
|
||||
ClassBase::Dynamic(_) => KnownClass::Type.to_instance(db),
|
||||
ClassBase::Class(class) => class.metaclass(db).to_instance(db),
|
||||
};
|
||||
other.is_disjoint_from(db, metaclass_instance_ty)
|
||||
}
|
||||
|
||||
(Type::KnownInstance(known_instance), Type::Instance(InstanceType { class }))
|
||||
|
|
|
@ -68,15 +68,6 @@ impl<'db> SubclassOfType<'db> {
|
|||
Type::from(self.subclass_of).member(db, name)
|
||||
}
|
||||
|
||||
/// A class `T` is an instance of its metaclass `U`,
|
||||
/// so the type `type[T]` is a subtype of the instance type `U`.
|
||||
pub(crate) fn as_instance_type_of_metaclass(&self, db: &'db dyn Db) -> Type<'db> {
|
||||
match self.subclass_of {
|
||||
ClassBase::Dynamic(_) => KnownClass::Type.to_instance(db),
|
||||
ClassBase::Class(class) => class.metaclass(db).to_instance(db),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return `true` if `self` is a subtype of `other`.
|
||||
///
|
||||
/// This can only return `true` if `self.subclass_of` is a [`ClassBase::Class`] variant;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue