| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Or we could do this? It feels slightly more elegant than the current implementation as well as fixing the issue, as an added bonus :-)
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -4,7 +4,7 @@ from __future__ import annotations
import itertools
from collections import defaultdict
-from contextlib import contextmanager, nullcontext
+from contextlib import ExitStack, contextmanager
from typing import (
AbstractSet,
Callable,
@@ -526,17 +526,12 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface):
# print("XXX in pass %d, class %s, function %s" %
# (self.pass_num, type_name, node.fullname or node.name))
done.add(node)
- with (
- self.tscope.class_scope(active_typeinfo)
- if active_typeinfo
- else nullcontext()
- ):
- with (
- self.scope.push_class(active_typeinfo)
- if active_typeinfo
- else nullcontext()
- ):
- self.check_partial(node)
+ with ExitStack() as stack:
+ if active_typeinfo:
+ stack.enter_context(self.tscope.class_scope(active_typeinfo))
+ stack.enter_context(self.scope.push_class(active_typeinfo))
+ self.check_partial(node)
+
return True
Sorry, something went wrong.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks!
Sorry, something went wrong.
|
Thank you both! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #16945