@@ -6549,7 +6549,10 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa
65496549 and not is_false_literal (expr )
65506550 and not is_true_literal (expr )
65516551 and not self .is_literal_enum (expr )
6552- and not (isinstance (expr_type , CallableType ) and expr_type .is_type_obj ())
6552+ and not (
6553+ isinstance (p_expr := get_proper_type (expr_type ), CallableType )
6554+ and p_expr .is_type_obj ()
6555+ )
65536556 ):
65546557 h = literal_hash (expr )
65556558 if h is not None :
@@ -6959,13 +6962,6 @@ def refine_identity_comparison_expression(
69596962 else :
69606963 type_targets .append ((i , TypeRange (expr_type , is_upper_bound = False )))
69616964
6962- if False :
6963- print ()
6964- print ("operands" , operands )
6965- print ("operand_types" , operand_types )
6966- print ("operator_specific_targets" , operator_specific_targets )
6967- print ("type_targets" , type_targets )
6968-
69696965 partial_type_maps = []
69706966
69716967 if operator_specific_targets :
@@ -6997,19 +6993,7 @@ def refine_identity_comparison_expression(
69976993 else_map = {}
69986994 partial_type_maps .append ((if_map , else_map ))
69996995
7000- final_if_map , final_else_map = reduce_conditional_maps (
7001- partial_type_maps , use_meet = len (operands ) > 2
7002- )
7003- if False :
7004- print (
7005- "final_if_map" ,
7006- {str (k ): str (v ) for k , v in final_if_map .items ()} if final_if_map else None ,
7007- )
7008- print (
7009- "final_else_map" ,
7010- {str (k ): str (v ) for k , v in final_else_map .items ()} if final_else_map else None ,
7011- )
7012- return final_if_map , final_else_map
6996+ return reduce_conditional_maps (partial_type_maps , use_meet = len (operands ) > 2 )
70136997
70146998 def refine_away_none_in_comparison (
70156999 self ,
@@ -8534,9 +8518,10 @@ def and_conditional_maps(m1: TypeMap, m2: TypeMap, use_meet: bool = False) -> Ty
85348518 for n1 in m1 :
85358519 for n2 in m2 :
85368520 if literal_hash (n1 ) == literal_hash (n2 ):
8537- result [ n1 ] = meet_types (m1 [n1 ], m2 [n2 ])
8538- if isinstance (result [ n1 ] , UninhabitedType ):
8521+ meet_result = meet_types (m1 [n1 ], m2 [n2 ])
8522+ if isinstance (meet_result , UninhabitedType ):
85398523 return None
8524+ result [n1 ] = meet_result
85408525 return result
85418526
85428527
@@ -8614,7 +8599,7 @@ def is_singleton_value(t: Type) -> bool:
86148599 "builtins.bytes" ,
86158600 "builtins.bytearray" ,
86168601 "builtins.memoryview" ,
8617- "builtins.tuple" ,
8602+ # for Collection[Never]
86188603 "builtins.list" ,
86198604 "builtins.dict" ,
86208605 "builtins.set" ,
@@ -8627,7 +8612,10 @@ def has_custom_eq_checks(t: Type) -> bool:
86278612 or custom_special_method (t , "__ne__" , check_all = False )
86288613 # TODO: make the hack more principled. explain what and why we're doing this though
86298614 # custom_special_method has special casing for builtins
8630- or (isinstance (t , Instance ) and t .type .fullname in BUILTINS_CUSTOM_EQ_CHECKS )
8615+ or (
8616+ isinstance (pt := get_proper_type (t ), Instance )
8617+ and pt .type .fullname in BUILTINS_CUSTOM_EQ_CHECKS
8618+ )
86318619 )
86328620
86338621
0 commit comments