MCPcopy
hub / github.com/python/mypy / wrap_context

Method wrap_context

mypy/build.py:3064–3093  ·  view source on GitHub ↗

Temporarily change the error import context to match this state. Also report an internal error if an unexpected exception was raised and raise an exception on a blocking error, unless check_blockers is False. Skipping blocking error reporting is used in the semantic

(self, check_blockers: bool = True)

Source from the content-addressed store, hash-verified

3062
3063 @contextlib.contextmanager
3064 def wrap_context(self, check_blockers: bool = True) -> Iterator[None]:
3065 """Temporarily change the error import context to match this state.
3066
3067 Also report an internal error if an unexpected exception was raised
3068 and raise an exception on a blocking error, unless
3069 check_blockers is False. Skipping blocking error reporting is used
3070 in the semantic analyzer so that we can report all blocking errors
3071 for a file (across multiple targets) to maintain backward
3072 compatibility.
3073 """
3074 save_import_context = self.manager.errors.import_context()
3075 self.manager.errors.set_import_context(self.import_context)
3076 try:
3077 yield
3078 except CompileError:
3079 raise
3080 except Exception as err:
3081 report_internal_error(
3082 err,
3083 self.path,
3084 0,
3085 self.manager.errors,
3086 self.options,
3087 self.manager.stdout,
3088 self.manager.stderr,
3089 )
3090 self.manager.errors.set_import_context(save_import_context)
3091 # TODO: Move this away once we've removed the old semantic analyzer?
3092 if check_blockers:
3093 self.check_blockers()
3094
3095 def load_fine_grained_deps(self) -> dict[str, set[str]]:
3096 return self.manager.load_fine_grained_deps(self.id)

Callers 15

get_sourceMethod · 0.95
parse_fileMethod · 0.95
type_check_first_passMethod · 0.95
finish_passesMethod · 0.95
parse_parallelMethod · 0.80
semantic_analyze_targetFunction · 0.80
check_type_argumentsFunction · 0.80

Calls 4

check_blockersMethod · 0.95
report_internal_errorFunction · 0.90
import_contextMethod · 0.80
set_import_contextMethod · 0.80

Tested by

no test coverage detected