@@ -794,8 +794,11 @@ impl<'db> Type<'db> {
794794 } ) ,
795795 ) => self_class. is_subclass_of ( db, target_class) ,
796796
797- // `Literal[str]` is a subtype of `type` because `str` is an instance of `type`.
798- // `Literal[enum.Enum]` is a subtype of `enum.EnumMeta` because `enum.Enum`
797+ // `type[str]` (== `SubclassOf("str")` in red-knot) describes all possible runtime subclasses
798+ // of the class object `str`. It is a subtype of `type` (== `Instance("type")`) because `str`
799+ // is an instance of `type`, and so all possible subclasses of `str` will also be instances of `type`.
800+ //
801+ // Similarly `type[enum.Enum]` is a subtype of `enum.EnumMeta` because `enum.Enum`
799802 // is an instance of `enum.EnumMeta`.
800803 (
801804 Type :: SubclassOf ( SubclassOfType {
@@ -810,14 +813,16 @@ impl<'db> Type<'db> {
810813 ( Type :: SubclassOf ( _) , _) => KnownClass :: Type . to_instance ( db) . is_subtype_of ( db, target) ,
811814
812815 // For example: `Type::KnownInstance(KnownInstanceType::Type)` is a subtype of `Type::Instance(_SpecialForm)`,
813- // because the symbol `typing.Type` is an instance of `typing._SpecialForm` at runtime
816+ // because `Type::KnownInstance(KnownInstanceType::Type)` is a set with exactly one runtime value in it
817+ // (the symbol `typing.Type`), and that symbol is known to be an instance of `typing._SpecialForm` at runtime.
814818 ( Type :: KnownInstance ( left) , right) => {
815819 left. instance_fallback ( db) . is_subtype_of ( db, right)
816820 }
817821
818- // For example, `Instance(ABCMeta)` is a subtype of `type[object]`,
819- // because (since `ABCMeta` subclasses `type`) all instances of `ABCMeta` are instances of `type`,
820- // and all instances of `type` are members of the type `type[object]`
822+ // For example, `abc.ABCMeta` (== `Instance("abc.ABCMeta")`) is a subtype of `type[object]`
823+ // (== `SubclassOf("object")`) because (since `abc.ABCMeta` subclasses `type`) all instances of `ABCMeta`
824+ // are instances of `type`, and `type[object]` represents the set of all subclasses of `object`,
825+ // which is exactly equal to the set of all instances of `type`.
821826 (
822827 Type :: Instance ( _) ,
823828 Type :: SubclassOf ( SubclassOfType {
@@ -827,7 +832,8 @@ impl<'db> Type<'db> {
827832 self . is_subtype_of ( db, KnownClass :: Type . to_instance ( db) )
828833 }
829834
830- // `bool` is a subtype of `int`, because all instances of `bool` are also instances of `int`.
835+ // `bool` is a subtype of `int`, because `bool` subclasses `int`,
836+ // which means that all instances of `bool` are also instances of `int`
831837 ( Type :: Instance ( self_instance) , Type :: Instance ( target_instance) ) => {
832838 self_instance. is_subtype_of ( db, target_instance)
833839 }
0 commit comments