@@ -465,7 +465,8 @@ pub enum Type<'db> {
465465 GenericAlias ( GenericAlias < ' db > ) ,
466466 /// The set of all class objects that are subclasses of the given class (C), spelled `type[C]`.
467467 SubclassOf ( SubclassOfType < ' db > ) ,
468- /// The set of Python objects with the given class in their __class__'s method resolution order
468+ /// The set of Python objects with the given class in their __class__'s method resolution order.
469+ /// Construct this variant using the `Type::instance` constructor function.
469470 Instance ( InstanceType < ' db > ) ,
470471 /// A single Python object that requires special treatment in the type system
471472 KnownInstance ( KnownInstanceType < ' db > ) ,
@@ -695,10 +696,6 @@ impl<'db> Type<'db> {
695696 )
696697 }
697698
698- pub const fn is_instance ( & self ) -> bool {
699- matches ! ( self , Type :: Instance ( ..) )
700- }
701-
702699 pub const fn is_property_instance ( & self ) -> bool {
703700 matches ! ( self , Type :: PropertyInstance ( ..) )
704701 }
@@ -799,13 +796,6 @@ impl<'db> Type<'db> {
799796 . expect ( "Expected a Type::IntLiteral variant" )
800797 }
801798
802- pub const fn into_instance ( self ) -> Option < InstanceType < ' db > > {
803- match self {
804- Type :: Instance ( instance_type) => Some ( instance_type) ,
805- _ => None ,
806- }
807- }
808-
809799 pub const fn into_known_instance ( self ) -> Option < KnownInstanceType < ' db > > {
810800 match self {
811801 Type :: KnownInstance ( known_instance) => Some ( known_instance) ,
@@ -1901,12 +1891,7 @@ impl<'db> Type<'db> {
19011891 other. is_disjoint_from ( db, KnownClass :: ModuleType . to_instance ( db) )
19021892 }
19031893
1904- ( Type :: Instance ( left_instance) , Type :: Instance ( right_instance) ) => {
1905- let left_class = left_instance. class ( ) ;
1906- let right_class = right_instance. class ( ) ;
1907- ( left_class. is_final ( db) && !left_class. is_subclass_of ( db, right_class) )
1908- || ( right_class. is_final ( db) && !right_class. is_subclass_of ( db, left_class) )
1909- }
1894+ ( Type :: Instance ( left) , Type :: Instance ( right) ) => left. is_disjoint_from ( db, right) ,
19101895
19111896 ( Type :: Tuple ( tuple) , Type :: Tuple ( other_tuple) ) => {
19121897 let self_elements = tuple. elements ( db) ;
@@ -2085,10 +2070,7 @@ impl<'db> Type<'db> {
20852070 false
20862071 }
20872072 Type :: DataclassDecorator ( _) | Type :: DataclassTransformer ( _) => false ,
2088- Type :: Instance ( instance) => instance
2089- . class ( )
2090- . known ( db)
2091- . is_some_and ( KnownClass :: is_singleton) ,
2073+ Type :: Instance ( instance) => instance. is_singleton ( db) ,
20922074 Type :: PropertyInstance ( _) => false ,
20932075 Type :: Tuple ( ..) => {
20942076 // The empty tuple is a singleton on CPython and PyPy, but not on other Python
@@ -2160,10 +2142,7 @@ impl<'db> Type<'db> {
21602142 . iter ( )
21612143 . all ( |elem| elem. is_single_valued ( db) ) ,
21622144
2163- Type :: Instance ( instance) => instance
2164- . class ( )
2165- . known ( db)
2166- . is_some_and ( KnownClass :: is_single_valued) ,
2145+ Type :: Instance ( instance) => instance. is_single_valued ( db) ,
21672146
21682147 Type :: BoundSuper ( _) => {
21692148 // At runtime two super instances never compare equal, even if their arguments are identical.
@@ -4633,8 +4612,8 @@ impl<'db> Type<'db> {
46334612 pub fn to_meta_type ( & self , db : & ' db dyn Db ) -> Type < ' db > {
46344613 match self {
46354614 Type :: Never => Type :: Never ,
4636- Type :: Instance ( instance) => SubclassOfType :: from ( db , instance. class ( ) ) ,
4637- Type :: KnownInstance ( known_instance) => known_instance. class ( ) . to_class_literal ( db) ,
4615+ Type :: Instance ( instance) => instance. to_meta_type ( db ) ,
4616+ Type :: KnownInstance ( known_instance) => known_instance. to_meta_type ( db) ,
46384617 Type :: PropertyInstance ( _) => KnownClass :: Property . to_class_literal ( db) ,
46394618 Type :: Union ( union) => union. map ( db, |ty| ty. to_meta_type ( db) ) ,
46404619 Type :: BooleanLiteral ( _) => KnownClass :: Bool . to_class_literal ( db) ,
0 commit comments