@@ -811,29 +811,6 @@ impl<'db> Type<'db> {
811811 }
812812 }
813813
814- /// Normalize the type `bool` -> `Literal[True, False]`.
815- ///
816- /// Using this method in various type-relational methods
817- /// ensures that the following invariants hold true:
818- ///
819- /// - bool ≡ Literal[True, False]
820- /// - bool | T ≡ Literal[True, False] | T
821- /// - bool <: Literal[True, False]
822- /// - bool | T <: Literal[True, False] | T
823- /// - Literal[True, False] <: bool
824- /// - Literal[True, False] | T <: bool | T
825- #[ must_use]
826- pub fn with_normalized_bools ( self , db : & ' db dyn Db ) -> Self {
827- match self {
828- Type :: Instance ( InstanceType { class } ) if class. is_known ( db, KnownClass :: Bool ) => {
829- Type :: normalized_bool ( db)
830- }
831- // TODO: decompose `LiteralString` into `Literal[""] | TruthyLiteralString`?
832- // We'd need to rename this method... --Alex
833- _ => self ,
834- }
835- }
836-
837814 /// Return a normalized version of `self` in which all unions and intersections are sorted
838815 /// according to a canonical order, no matter how "deeply" a union/intersection may be nested.
839816 #[ must_use]
@@ -905,10 +882,11 @@ impl<'db> Type<'db> {
905882 ( _, Type :: Never ) => false ,
906883
907884 ( Type :: Instance ( InstanceType { class } ) , _) if class. is_known ( db, KnownClass :: Bool ) => {
908- Type :: normalized_bool ( db) . is_subtype_of ( db, target)
885+ Type :: BooleanLiteral ( true ) . is_subtype_of ( db, target)
886+ && Type :: BooleanLiteral ( false ) . is_subtype_of ( db, target)
909887 }
910888 ( _, Type :: Instance ( InstanceType { class } ) ) if class. is_known ( db, KnownClass :: Bool ) => {
911- self . is_subtype_of ( db , Type :: normalized_bool ( db ) )
889+ self . is_boolean_literal ( )
912890 }
913891
914892 ( Type :: Union ( union) , _) => union
@@ -1125,10 +1103,12 @@ impl<'db> Type<'db> {
11251103 }
11261104
11271105 ( Type :: Instance ( InstanceType { class } ) , _) if class. is_known ( db, KnownClass :: Bool ) => {
1128- Type :: normalized_bool ( db) . is_assignable_to ( db, target)
1106+ Type :: BooleanLiteral ( true ) . is_assignable_to ( db, target)
1107+ && Type :: BooleanLiteral ( false ) . is_assignable_to ( db, target)
11291108 }
11301109 ( _, Type :: Instance ( InstanceType { class } ) ) if class. is_known ( db, KnownClass :: Bool ) => {
1131- self . is_assignable_to ( db, Type :: normalized_bool ( db) )
1110+ self . is_assignable_to ( db, Type :: BooleanLiteral ( true ) )
1111+ || self . is_assignable_to ( db, Type :: BooleanLiteral ( false ) )
11321112 }
11331113
11341114 // A union is assignable to a type T iff every element of the union is assignable to T.
@@ -2409,13 +2389,6 @@ impl<'db> Type<'db> {
24092389 KnownClass :: NoneType . to_instance ( db)
24102390 }
24112391
2412- /// The type `Literal[True, False]`, which is exactly equivalent to `bool`
2413- /// (and which `bool` is eagerly normalized to in several situations)
2414- pub fn normalized_bool ( db : & ' db dyn Db ) -> Type < ' db > {
2415- const LITERAL_BOOLS : [ Type ; 2 ] = [ Type :: BooleanLiteral ( false ) , Type :: BooleanLiteral ( true ) ] ;
2416- Type :: Union ( UnionType :: new ( db, Box :: from ( LITERAL_BOOLS ) ) )
2417- }
2418-
24192392 /// Return the type of `tuple(sys.version_info)`.
24202393 ///
24212394 /// This is not exactly the type that `sys.version_info` has at runtime,
0 commit comments