@@ -1093,18 +1093,20 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
1093
1093
ctx = self .chk .type_context [- 1 ]
1094
1094
left_type = self .accept (e .left , ctx )
1095
1095
1096
+ assert e .op in ('and' , 'or' ) # Checked by visit_op_expr
1097
+
1096
1098
if e .op == 'and' :
1097
1099
right_map , left_map = \
1098
1100
mypy .checker .find_isinstance_check (e .left , self .chk .type_map ,
1099
1101
self .chk .typing_mode_weak ())
1100
- truthiness_restriction = false_only
1102
+ restricted_left_type = false_only (left_type )
1103
+ result_is_left = not left_type .can_be_true
1101
1104
elif e .op == 'or' :
1102
1105
left_map , right_map = \
1103
1106
mypy .checker .find_isinstance_check (e .left , self .chk .type_map ,
1104
1107
self .chk .typing_mode_weak ())
1105
- truthiness_restriction = true_only
1106
- # type_restriction tells about the possible truth values of the left operand
1107
- # if that's the result of the boolean operation
1108
+ restricted_left_type = true_only (left_type )
1109
+ result_is_left = not left_type .can_be_false
1108
1110
1109
1111
with self .chk .binder .frame_context ():
1110
1112
if right_map :
@@ -1125,12 +1127,10 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
1125
1127
assert right_map is not None # find_isinstance_check guarantees this
1126
1128
return right_type
1127
1129
1128
- restricted_left_type = truthiness_restriction (left_type )
1129
-
1130
1130
if isinstance (restricted_left_type , UninhabitedType ):
1131
1131
# The left operand can never be the result
1132
1132
return right_type
1133
- elif left_type is restricted_left_type :
1133
+ elif result_is_left :
1134
1134
# The left operand is always the result
1135
1135
return left_type
1136
1136
else :
0 commit comments