Skip to content

Commit c7a2b5c

Browse files
committed
Remove context manager from analyze_cond_branch call
1 parent db29355 commit c7a2b5c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

mypy/checkexpr.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,10 +2806,12 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
28062806
left_map = None
28072807

28082808
if right_map is None:
2809-
with self.msg.disable_errors():
2810-
right_type = self.analyze_cond_branch(right_map, e.right, left_type)
2811-
else:
2809+
self.msg.disable_errors1()
2810+
try:
28122811
right_type = self.analyze_cond_branch(right_map, e.right, left_type)
2812+
finally:
2813+
if right_map is None:
2814+
self.msg.enable_errors()
28132815

28142816
if right_map is None:
28152817
# The boolean expression is statically known to be the left value

mypy/messages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,19 @@ def add_errors(self, messages: 'MessageBuilder') -> None:
137137
for info in errs:
138138
self.errors.add_error_info(info)
139139

140+
def disable_errors1(self) -> None:
141+
self.disable_count += 1
142+
140143
@contextmanager
141144
def disable_errors(self) -> Iterator[None]:
142145
self.disable_count += 1
143146
try:
144147
yield
145148
finally:
146149
self.disable_count -= 1
150+
151+
def enable_errors(self) -> None:
152+
self.disable_count -= 1
147153

148154
def is_errors(self) -> bool:
149155
return self.errors.is_errors()

0 commit comments

Comments
 (0)