Skip to content

Commit 2037e4a

Browse files
authored
Workaround parenthesised context manager issue (#16949)
Fixes #16945
1 parent 790e8a7 commit 2037e4a

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

mypy/checker.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import itertools
66
from collections import defaultdict
7-
from contextlib import contextmanager, nullcontext
7+
from contextlib import ExitStack, contextmanager
88
from typing import (
99
AbstractSet,
1010
Callable,
@@ -526,17 +526,11 @@ def check_second_pass(
526526
# print("XXX in pass %d, class %s, function %s" %
527527
# (self.pass_num, type_name, node.fullname or node.name))
528528
done.add(node)
529-
with (
530-
self.tscope.class_scope(active_typeinfo)
531-
if active_typeinfo
532-
else nullcontext()
533-
):
534-
with (
535-
self.scope.push_class(active_typeinfo)
536-
if active_typeinfo
537-
else nullcontext()
538-
):
539-
self.check_partial(node)
529+
with ExitStack() as stack:
530+
if active_typeinfo:
531+
stack.enter_context(self.tscope.class_scope(active_typeinfo))
532+
stack.enter_context(self.scope.push_class(active_typeinfo))
533+
self.check_partial(node)
540534
return True
541535

542536
def check_partial(self, node: DeferredNodeType | FineGrainedDeferredNodeType) -> None:

0 commit comments

Comments
 (0)