@@ -2741,6 +2741,17 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
27412741 restricted_left_type = true_only (left_type )
27422742 result_is_left = not left_type .can_be_false
27432743
2744+ # If left_map is None then we know mypy considers the left expression
2745+ # to be redundant.
2746+ #
2747+ # Note that we perform these checks *before* we take into account
2748+ # the analysis from the semanal phase below. We assume that nodes
2749+ # marked as unreachable during semantic analysis were done so intentionally.
2750+ # So, we shouldn't report an error.
2751+ if codes .REDUNDANT_EXPR in self .chk .options .enabled_error_codes :
2752+ if left_map is None :
2753+ self .msg .redundant_left_operand (e .op , e .left )
2754+
27442755 # If right_map is None then we know mypy considers the right branch
27452756 # to be unreachable and therefore any errors found in the right branch
27462757 # should be suppressed.
@@ -2750,10 +2761,8 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
27502761 # marked as unreachable during semantic analysis were done so intentionally.
27512762 # So, we shouldn't report an error.
27522763 if self .chk .options .warn_unreachable :
2753- if left_map is None :
2754- self .msg .redundant_left_operand (e .op , e .left )
27552764 if right_map is None :
2756- self .msg .redundant_right_operand (e .op , e .right )
2765+ self .msg .unreachable_right_operand (e .op , e .right )
27572766
27582767 if e .right_unreachable :
27592768 right_map = None
@@ -3674,7 +3683,7 @@ def check_for_comp(self, e: Union[GeneratorExpr, DictionaryComprehension]) -> No
36743683 for var , type in true_map .items ():
36753684 self .chk .binder .put (var , type )
36763685
3677- if self .chk .options .warn_unreachable :
3686+ if codes . REDUNDANT_EXPR in self .chk .options .enabled_error_codes :
36783687 if true_map is None :
36793688 self .msg .redundant_condition_in_comprehension (False , condition )
36803689 elif false_map is None :
@@ -3687,7 +3696,7 @@ def visit_conditional_expr(self, e: ConditionalExpr, allow_none_return: bool = F
36873696 # Gain type information from isinstance if it is there
36883697 # but only for the current expression
36893698 if_map , else_map = self .chk .find_isinstance_check (e .cond )
3690- if self .chk .options .warn_unreachable :
3699+ if codes . REDUNDANT_EXPR in self .chk .options .enabled_error_codes :
36913700 if if_map is None :
36923701 self .msg .redundant_condition_in_if (False , e .cond )
36933702 elif else_map is None :
0 commit comments