@@ -1167,6 +1167,10 @@ impl<'db> Type<'db> {
11671167 }
11681168
11691169 ( Type :: SubclassOf ( _) , other) | ( other, Type :: SubclassOf ( _) ) => {
1170+ // TODO we could do better here: if both variants are `SubclassOf` and they have different "solid bases",
1171+ // multiple inheritance between the two is impossible, so they are disjoint.
1172+ //
1173+ // Note that `type[<@final class>]` is eagerly simplified to `Literal[<@final class>]` by [`SubclassOfType::from`].
11701174 other. is_disjoint_from ( db, KnownClass :: Type . to_instance ( db) )
11711175 }
11721176
@@ -2114,8 +2118,8 @@ impl<'db> Type<'db> {
21142118 } ,
21152119
21162120 Type :: StringLiteral ( _) | Type :: LiteralString => KnownClass :: Str . to_class_literal ( db) ,
2117- Type :: Any => SubclassOfType :: from ( db , ClassBase :: Any ) ,
2118- Type :: Unknown => SubclassOfType :: from ( db , ClassBase :: Unknown ) ,
2121+ Type :: Any => SubclassOfType :: subclass_of_any ( ) ,
2122+ Type :: Unknown => SubclassOfType :: subclass_of_unknown ( ) ,
21192123 // TODO intersections
21202124 Type :: Intersection ( _) => SubclassOfType :: from (
21212125 db,
@@ -2333,7 +2337,7 @@ impl<'db> KnownClass {
23332337 self . to_class_literal ( db)
23342338 . into_class_literal ( )
23352339 . map ( |ClassLiteralType { class } | SubclassOfType :: from ( db, class) )
2336- . unwrap_or_else ( || SubclassOfType :: from ( db , ClassBase :: Unknown ) )
2340+ . unwrap_or_else ( SubclassOfType :: subclass_of_unknown )
23372341 }
23382342
23392343 /// Return `true` if this symbol can be resolved to a class definition `class` in typeshed,
@@ -2731,6 +2735,7 @@ impl<'db> KnownInstanceType<'db> {
27312735 self . class ( ) . to_instance ( db)
27322736 }
27332737
2738+ /// Return `true` if this symbol is an instance of `class`.
27342739 pub fn is_instance_of ( self , db : & ' db dyn Db , class : Class < ' db > ) -> bool {
27352740 self . class ( ) . is_subclass_of ( db, class)
27362741 }
@@ -3324,7 +3329,7 @@ impl<'db> Class<'db> {
33243329 /// Return the metaclass of this class, or `type[Unknown]` if the metaclass cannot be inferred.
33253330 pub ( crate ) fn metaclass ( self , db : & ' db dyn Db ) -> Type < ' db > {
33263331 self . try_metaclass ( db)
3327- . unwrap_or_else ( |_| SubclassOfType :: from ( db , ClassBase :: Unknown ) )
3332+ . unwrap_or_else ( |_| SubclassOfType :: subclass_of_unknown ( ) )
33283333 }
33293334
33303335 /// Return the metaclass of this class, or an error if the metaclass cannot be inferred.
@@ -3337,7 +3342,7 @@ impl<'db> Class<'db> {
33373342 // We emit diagnostics for cyclic class definitions elsewhere.
33383343 // Avoid attempting to infer the metaclass if the class is cyclically defined:
33393344 // it would be easy to enter an infinite loop.
3340- return Ok ( SubclassOfType :: from ( db , ClassBase :: Unknown ) ) ;
3345+ return Ok ( SubclassOfType :: subclass_of_unknown ( ) ) ;
33413346 }
33423347
33433348 let explicit_metaclass = self . explicit_metaclass ( db) ;
@@ -3786,8 +3791,8 @@ pub(crate) mod tests {
37863791 let elements = tys. into_iter ( ) . map ( |ty| ty. into_type ( db) ) ;
37873792 TupleType :: from_elements ( db, elements)
37883793 }
3789- Ty :: SubclassOfAny => SubclassOfType :: from ( db , ClassBase :: Any ) ,
3790- Ty :: SubclassOfUnknown => SubclassOfType :: from ( db , ClassBase :: Unknown ) ,
3794+ Ty :: SubclassOfAny => SubclassOfType :: subclass_of_any ( ) ,
3795+ Ty :: SubclassOfUnknown => SubclassOfType :: subclass_of_unknown ( ) ,
37913796 Ty :: SubclassOfBuiltinClass ( s) => SubclassOfType :: from (
37923797 db,
37933798 builtins_symbol ( db, s)
0 commit comments