@@ -6977,35 +6977,32 @@ def refine_identity_comparison_expression(
69776977 continue
69786978 targets = [t for j , t in operator_specific_targets if j != i ]
69796979 if targets :
6980- expr_type = coerce_to_literal (operand_types [i ])
6981- expr_type = try_expanding_sum_type_to_union (expr_type , None )
6982- if_map , else_map = conditional_types_to_typemaps (
6983- operands [i ], * conditional_types (expr_type , targets )
6984- )
6985- # print("ooo if_map", if_map)
6986- # print("ooo else_map", else_map)
6987- partial_type_maps .append ((if_map , else_map ))
6980+ for target in targets :
6981+ expr_type = coerce_to_literal (operand_types [i ])
6982+ expr_type = try_expanding_sum_type_to_union (expr_type , None )
6983+ if_map , else_map = conditional_types_to_typemaps (
6984+ operands [i ], * conditional_types (expr_type , [target ])
6985+ )
6986+ partial_type_maps .append ((if_map , else_map ))
69886987
69896988 if type_targets :
69906989 for i in chain_indices :
69916990 if i not in narrowable_operand_indices :
69926991 continue
69936992 targets = [t for j , t in type_targets if j != i ]
69946993 if targets :
6995- expr_type = operand_types [i ]
6996- if_map , else_map = conditional_types_to_typemaps (
6997- operands [i ], * conditional_types (expr_type , targets )
6998- )
6999- if if_map :
7000- else_map = {}
7001- # print("ttt targets", targets)
7002- # print("ttt if_map", if_map)
7003- # print("ttt else_map", else_map)
7004- partial_type_maps .append ((if_map , else_map ))
6994+ for target in targets :
6995+ expr_type = operand_types [i ]
6996+ if_map , else_map = conditional_types_to_typemaps (
6997+ operands [i ], * conditional_types (expr_type , [target ])
6998+ )
6999+ if if_map :
7000+ else_map = {}
7001+ partial_type_maps .append ((if_map , else_map ))
70057002
7006- final_if_map , final_else_map = reduce_conditional_maps (partial_type_maps )
7007- # print("final_if_map", final_if_map)
7008- # print("final_else_map", final_else_map)
7003+ final_if_map , final_else_map = reduce_conditional_maps (partial_type_maps , use_meet = len ( operands ) > 2 )
7004+ # print("final_if_map", {str(k): str(v) for k, v in final_if_map.items()} )
7005+ # print("final_else_map", {str(k): str(v) for k, v in final_else_map.items()} )
70097006 return final_if_map , final_else_map
70107007
70117008 def refine_away_none_in_comparison (
@@ -8532,6 +8529,8 @@ def and_conditional_maps(m1: TypeMap, m2: TypeMap, use_meet: bool = False) -> Ty
85328529 for n2 in m2 :
85338530 if literal_hash (n1 ) == literal_hash (n2 ):
85348531 result [n1 ] = meet_types (m1 [n1 ], m2 [n2 ])
8532+ if isinstance (result [n1 ], UninhabitedType ):
8533+ return None
85358534 return result
85368535
85378536
@@ -8602,10 +8601,7 @@ def reduce_conditional_maps(
86028601
86038602def is_singleton_value (t : Type ) -> bool :
86048603 t = get_proper_type (t )
8605- # TODO: check the type object thing
8606- ret = isinstance (t , LiteralType ) or t .is_singleton_type () or (isinstance (t , CallableType ) and t .is_type_obj ())
8607- # print("!!!", t, type(t), ret)
8608- return ret
8604+ return isinstance (t , LiteralType ) or t .is_singleton_type ()
86098605
86108606
86118607BUILTINS_CUSTOM_EQ_CHECKS : Final = {
0 commit comments