@@ -2740,6 +2740,17 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
27402740 restricted_left_type = true_only (left_type )
27412741 result_is_left = not left_type .can_be_false
27422742
2743+ # If left_map is None then we know mypy considers the left expression
2744+ # to be reundant.
2745+ #
2746+ # Note that we perform these checks *before* we take into account
2747+ # the analysis from the semanal phase below. We assume that nodes
2748+ # marked as unreachable during semantic analysis were done so intentionally.
2749+ # So, we shouldn't report an error.
2750+ if self .chk .options .warn_redundant_expr :
2751+ if left_map is None :
2752+ self .msg .redundant_left_operand (e .op , e .left )
2753+
27432754 # If right_map is None then we know mypy considers the right branch
27442755 # to be unreachable and therefore any errors found in the right branch
27452756 # should be suppressed.
@@ -2749,10 +2760,8 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
27492760 # marked as unreachable during semantic analysis were done so intentionally.
27502761 # So, we shouldn't report an error.
27512762 if self .chk .options .warn_unreachable :
2752- if left_map is None :
2753- self .msg .redundant_left_operand (e .op , e .left )
27542763 if right_map is None :
2755- self .msg .redundant_right_operand (e .op , e .right )
2764+ self .msg .unreachable_right_operand (e .op , e .right )
27562765
27572766 if e .right_unreachable :
27582767 right_map = None
@@ -3669,7 +3678,7 @@ def check_for_comp(self, e: Union[GeneratorExpr, DictionaryComprehension]) -> No
36693678 for var , type in true_map .items ():
36703679 self .chk .binder .put (var , type )
36713680
3672- if self .chk .options .warn_unreachable :
3681+ if self .chk .options .warn_redundant_expr :
36733682 if true_map is None :
36743683 self .msg .redundant_condition_in_comprehension (False , condition )
36753684 elif false_map is None :
@@ -3682,7 +3691,7 @@ def visit_conditional_expr(self, e: ConditionalExpr, allow_none_return: bool = F
36823691 # Gain type information from isinstance if it is there
36833692 # but only for the current expression
36843693 if_map , else_map = self .chk .find_isinstance_check (e .cond )
3685- if self .chk .options .warn_unreachable :
3694+ if self .chk .options .warn_redundant_expr :
36863695 if if_map is None :
36873696 self .msg .redundant_condition_in_if (False , e .cond )
36883697 elif else_map is None :
0 commit comments