@@ -5836,9 +5836,13 @@ def visit_conditional_expr(self, e: ConditionalExpr, allow_none_return: bool = F
58365836 # but only for the current expression
58375837 if_map , else_map = self .chk .find_isinstance_check (e .cond )
58385838 if codes .REDUNDANT_EXPR in self .chk .options .enabled_error_codes :
5839- if if_map is None :
5839+ if if_map is None or any (
5840+ isinstance (get_proper_type (t ), UninhabitedType ) for t in if_map .values ()
5841+ ):
58405842 self .msg .redundant_condition_in_if (False , e .cond )
5841- elif else_map is None :
5843+ elif else_map is None or any (
5844+ isinstance (get_proper_type (t ), UninhabitedType ) for t in else_map .values ()
5845+ ):
58425846 self .msg .redundant_condition_in_if (True , e .cond )
58435847
58445848 if_type = self .analyze_cond_branch (
@@ -5915,17 +5919,28 @@ def analyze_cond_branch(
59155919 node : Expression ,
59165920 context : Type | None ,
59175921 allow_none_return : bool = False ,
5918- suppress_unreachable_errors : bool = True ,
5922+ suppress_unreachable_errors : bool | None = None ,
59195923 ) -> Type :
5924+ # TODO: default based on flag (default to `True` if flag is not passed)
5925+ unreachable_errors_suppressed = (
5926+ suppress_unreachable_errors
5927+ if suppress_unreachable_errors is not None
5928+ else self .chk .binder .is_unreachable_warning_suppressed ()
5929+ )
59205930 with self .chk .binder .frame_context (can_skip = True , fall_through = 0 ):
5921- if map is None :
5931+ self .chk .push_type_map (map )
5932+
5933+ if map is None or any (
5934+ isinstance (get_proper_type (t ), UninhabitedType ) for t in map .values ()
5935+ ):
59225936 # We still need to type check node, in case we want to
59235937 # process it for isinstance checks later. Since the branch was
59245938 # determined to be unreachable, any errors should be suppressed.
5925- with self .msg .filter_errors (filter_errors = suppress_unreachable_errors ):
5939+
5940+ with self .msg .filter_errors (filter_errors = unreachable_errors_suppressed ):
59265941 self .accept (node , type_context = context , allow_none_return = allow_none_return )
59275942 return UninhabitedType ()
5928- self . chk . push_type_map ( map )
5943+
59295944 return self .accept (node , type_context = context , allow_none_return = allow_none_return )
59305945
59315946 #
0 commit comments