Skip to content

Commit e8fbe26

Browse files
committed
Apply wrap context more consistently
1 parent 1879228 commit e8fbe26

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

mypy/build.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,14 +3137,15 @@ def detect_possibly_undefined_vars(self) -> None:
31373137
if manager.errors.is_error_code_enabled(
31383138
codes.POSSIBLY_UNDEFINED
31393139
) or manager.errors.is_error_code_enabled(codes.USED_BEFORE_DEF):
3140-
self.tree.accept(
3141-
PossiblyUndefinedVariableVisitor(
3142-
MessageBuilder(manager.errors, manager.modules),
3143-
self.type_map(),
3144-
self.options,
3145-
self.tree.names,
3140+
with self.wrap_context():
3141+
self.tree.accept(
3142+
PossiblyUndefinedVariableVisitor(
3143+
MessageBuilder(manager.errors, manager.modules),
3144+
self.type_map(),
3145+
self.options,
3146+
self.tree.names,
3147+
)
31463148
)
3147-
)
31483149

31493150
def finish_passes(self) -> None:
31503151
assert self.tree is not None, "Internal error: method must be called on parsed file only"
@@ -3366,14 +3367,16 @@ def generate_unused_ignore_notes(self) -> None:
33663367
if self.meta and self.options.fine_grained_incremental:
33673368
self.verify_dependencies(suppressed_only=True)
33683369
is_typeshed = self.tree is not None and self.tree.is_typeshed_file(self.options)
3369-
self.manager.errors.generate_unused_ignore_errors(self.xpath, is_typeshed)
3370+
with self.wrap_context():
3371+
self.manager.errors.generate_unused_ignore_errors(self.xpath, is_typeshed)
33703372

33713373
def generate_ignore_without_code_notes(self) -> None:
33723374
if self.manager.errors.is_error_code_enabled(codes.IGNORE_WITHOUT_CODE):
33733375
is_typeshed = self.tree is not None and self.tree.is_typeshed_file(self.options)
3374-
self.manager.errors.generate_ignore_without_code_errors(
3375-
self.xpath, self.options.warn_unused_ignores, is_typeshed
3376-
)
3376+
with self.wrap_context():
3377+
self.manager.errors.generate_ignore_without_code_errors(
3378+
self.xpath, self.options.warn_unused_ignores, is_typeshed
3379+
)
33773380

33783381

33793382
# Module import and diagnostic glue
@@ -3678,12 +3681,14 @@ def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: S
36783681
# immediately if it's empty or only contains comments.
36793682
# But beware, some package may be the ancestor of many modules,
36803683
# so we'd need to cache the decision.
3684+
save_import_context = manager.errors.import_context()
36813685
manager.errors.set_import_context([])
36823686
manager.errors.set_file(ancestor_for.xpath, ancestor_for.id, manager.options)
36833687
manager.error(None, f'Ancestor package "{id}" ignored', only_once=True)
36843688
manager.note(
36853689
None, "(Using --follow-imports=error, submodule passed on command line)", only_once=True
36863690
)
3691+
manager.errors.set_import_context(save_import_context)
36873692

36883693

36893694
def log_configuration(manager: BuildManager, sources: list[BuildSource]) -> None:

mypy/semanal_main.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,18 @@ def apply_class_plugin_hooks(graph: Graph, scc: list[str], errors: Errors) -> No
463463
state = graph[module]
464464
tree = state.tree
465465
assert tree
466-
for _, node, _ in tree.local_definitions():
467-
if isinstance(node.node, TypeInfo):
468-
if not apply_hooks_to_class(
469-
state.manager.semantic_analyzer,
470-
module,
471-
node.node,
472-
state.options,
473-
tree,
474-
errors,
475-
):
476-
incomplete = True
466+
with state.wrap_context():
467+
for _, node, _ in tree.local_definitions():
468+
if isinstance(node.node, TypeInfo):
469+
if not apply_hooks_to_class(
470+
state.manager.semantic_analyzer,
471+
module,
472+
node.node,
473+
state.options,
474+
tree,
475+
errors,
476+
):
477+
incomplete = True
477478

478479

479480
def apply_hooks_to_class(

0 commit comments

Comments
 (0)