|
64 | 64 | FunctionContext, FunctionSigContext,
|
65 | 65 | )
|
66 | 66 | from mypy.typeops import (
|
67 |
| - tuple_fallback, make_simplified_union, true_only, false_only, erase_to_union_or_bound, |
68 |
| - function_type, callable_type, try_getting_str_literals, custom_special_method, |
| 67 | + try_expanding_sum_type_to_union, tuple_fallback, make_simplified_union, |
| 68 | + true_only, false_only, erase_to_union_or_bound, function_type, |
| 69 | + callable_type, try_getting_str_literals, custom_special_method, |
69 | 70 | is_literal_type_like,
|
70 | 71 | )
|
71 | 72 | import mypy.errorcodes as codes
|
@@ -2783,6 +2784,9 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
|
2783 | 2784 | # '[1] or []' are inferred correctly.
|
2784 | 2785 | ctx = self.type_context[-1]
|
2785 | 2786 | left_type = self.accept(e.left, ctx)
|
| 2787 | + expanded_left_type = try_expanding_sum_type_to_union( |
| 2788 | + self.accept(e.left, ctx), "builtins.bool" |
| 2789 | + ) |
2786 | 2790 |
|
2787 | 2791 | assert e.op in ('and', 'or') # Checked by visit_op_expr
|
2788 | 2792 |
|
@@ -2817,7 +2821,7 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
|
2817 | 2821 | # to be unreachable and therefore any errors found in the right branch
|
2818 | 2822 | # should be suppressed.
|
2819 | 2823 | with (self.msg.disable_errors() if right_map is None else nullcontext()):
|
2820 |
| - right_type = self.analyze_cond_branch(right_map, e.right, left_type) |
| 2824 | + right_type = self.analyze_cond_branch(right_map, e.right, expanded_left_type) |
2821 | 2825 |
|
2822 | 2826 | if right_map is None:
|
2823 | 2827 | # The boolean expression is statically known to be the left value
|
|
0 commit comments