@@ -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
36893694def log_configuration (manager : BuildManager , sources : list [BuildSource ]) -> None :
0 commit comments