@@ -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
@@ -3673,7 +3682,7 @@ def check_for_comp(self, e: Union[GeneratorExpr, DictionaryComprehension]) -> No
36733682 for var , type in true_map .items ():
36743683 self .chk .binder .put (var , type )
36753684
3676- if self .chk .options .warn_unreachable :
3685+ if self .chk .options .warn_redundant_expr :
36773686 if true_map is None :
36783687 self .msg .redundant_condition_in_comprehension (False , condition )
36793688 elif false_map is None :
@@ -3686,7 +3695,7 @@ def visit_conditional_expr(self, e: ConditionalExpr, allow_none_return: bool = F
36863695 # Gain type information from isinstance if it is there
36873696 # but only for the current expression
36883697 if_map , else_map = self .chk .find_isinstance_check (e .cond )
3689- if self .chk .options .warn_unreachable :
3698+ if self .chk .options .warn_redundant_expr :
36903699 if if_map is None :
36913700 self .msg .redundant_condition_in_if (False , e .cond )
36923701 elif else_map is None :
0 commit comments