diff --git a/crates/red_knot_python_semantic/src/types.rs b/crates/red_knot_python_semantic/src/types.rs index 310d483e894c1d..031ad5ab45312b 100644 --- a/crates/red_knot_python_semantic/src/types.rs +++ b/crates/red_knot_python_semantic/src/types.rs @@ -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 })) diff --git a/crates/red_knot_python_semantic/src/types/subclass_of.rs b/crates/red_knot_python_semantic/src/types/subclass_of.rs index 6ea9817107b129..fe5cc5cd98629b 100644 --- a/crates/red_knot_python_semantic/src/types/subclass_of.rs +++ b/crates/red_knot_python_semantic/src/types/subclass_of.rs @@ -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;