MCPcopy Index your code
hub / github.com/python/mypy / write_cache

Method write_cache

mypy/build.py:3583–3631  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3581 return buf.getvalue()
3582
3583 def write_cache(self) -> tuple[CacheMeta, str] | None:
3584 assert self.tree is not None, "Internal error: method must be called on parsed file only"
3585 # We don't support writing cache files in fine-grained incremental mode.
3586 if (
3587 not self.path
3588 or self.options.cache_dir == os.devnull
3589 or self.options.fine_grained_incremental
3590 ):
3591 if self.options.debug_serialize:
3592 try:
3593 if self.manager.options.fixed_format_cache:
3594 data = WriteBuffer()
3595 self.tree.write(data)
3596 else:
3597 self.tree.serialize()
3598 except Exception:
3599 print(f"Error serializing {self.id}", file=self.manager.stdout)
3600 raise # Propagate to display traceback
3601 return None
3602 dep_prios = self.dependency_priorities()
3603 dep_lines = self.dependency_lines()
3604 assert self.source_hash is not None
3605 assert len(set(self.dependencies)) == len(
3606 self.dependencies
3607 ), f"Duplicates in dependencies list for {self.id} ({self.dependencies})"
3608 new_interface_hash, meta_tuple = write_cache(
3609 self.id,
3610 self.path,
3611 self.tree,
3612 # Indirect dependencies are stored separately as part of CacheMetaEx.
3613 [dep for dep in self.dependencies if self.priorities.get(dep) != PRI_INDIRECT],
3614 [dep for dep in self.suppressed if self.priorities.get(dep) != PRI_INDIRECT],
3615 self.suppressed_deps_opts(),
3616 self.imports_ignored,
3617 dep_prios,
3618 dep_lines,
3619 self.interface_hash,
3620 self.trans_dep_hash,
3621 self.source_hash,
3622 self.ignore_all,
3623 self.manager,
3624 )
3625 if new_interface_hash == self.interface_hash:
3626 self.manager.log(f"Cached module {self.id} has same interface")
3627 else:
3628 self.manager.log(f"Cached module {self.id} has changed interface")
3629 self.mark_interface_stale()
3630 self.interface_hash = new_interface_hash
3631 return meta_tuple
3632
3633 def verify_dependencies(self, suppressed_only: bool = False) -> None:
3634 """Report errors for import targets in modules that don't exist.

Callers 2

process_stale_sccFunction · 0.80

Calls 12

dependency_prioritiesMethod · 0.95
dependency_linesMethod · 0.95
suppressed_deps_optsMethod · 0.95
mark_interface_staleMethod · 0.95
printFunction · 0.85
lenFunction · 0.85
setClass · 0.85
write_cacheFunction · 0.70
writeMethod · 0.45
serializeMethod · 0.45
getMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected