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

Function load_states

mypy/build_worker/worker.py:268–311  ·  view source on GitHub ↗

Re-create full state of an SCC as it would have been in coordinator.

(
    mod_ids: list[str],
    graph: Graph,
    manager: BuildManager,
    import_errors: dict[str, list[ErrorInfo]],
    mod_data: dict[str, tuple[bytes, FileRawData | None]],
)

Source from the content-addressed store, hash-verified

266
267
268def load_states(
269 mod_ids: list[str],
270 graph: Graph,
271 manager: BuildManager,
272 import_errors: dict[str, list[ErrorInfo]],
273 mod_data: dict[str, tuple[bytes, FileRawData | None]],
274) -> None:
275 """Re-create full state of an SCC as it would have been in coordinator."""
276 if platform.python_implementation() == "CPython":
277 # Run full collection after previous SCC batch, everything that survives
278 # will be put into permanent generation below, since we don't free anything
279 # after SCC processing is done.
280 gc.collect()
281 gc.disable()
282 needs_parse = []
283 for id in mod_ids:
284 state = graph[id]
285 # Re-clone options since we don't send them, it is usually faster than deserializing.
286 state.options = state.options.clone_for_module(state.id)
287 suppressed_deps_opts, raw_data = mod_data[id]
288 if raw_data is not None:
289 state.parse_file(raw_data=raw_data)
290 else:
291 needs_parse.append(state)
292 # Set data that is needed to be written to cache meta.
293 state.known_suppressed_deps_opts = suppressed_deps_opts
294 # Perform actual parsing in parallel (but we don't need to compute dependencies).
295 if needs_parse:
296 manager.parse_all(needs_parse, post_parse=False)
297 for id in mod_ids:
298 state = graph[id]
299 assert state.tree is not None
300 import_lines = {imp.line for imp in state.tree.imports}
301 state.imports_ignored = {
302 line: codes for line, codes in state.tree.ignored_lines.items() if line in import_lines
303 }
304 # Replay original errors encountered during graph loading in coordinator.
305 if id in import_errors:
306 manager.errors.set_file(state.xpath, id, state.options)
307 for err_info in import_errors[id]:
308 manager.errors.add_error_info(err_info)
309 if platform.python_implementation() == "CPython":
310 gc.freeze()
311 gc.enable()
312
313
314def setup_worker_manager(sources: list[BuildSource], ctx: ServerContext) -> BuildManager | None:

Callers 1

serveFunction · 0.85

Calls 8

clone_for_moduleMethod · 0.80
appendMethod · 0.80
parse_allMethod · 0.80
set_fileMethod · 0.80
add_error_infoMethod · 0.80
collectMethod · 0.45
parse_fileMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…