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

Function load

misc/diff-cache.py:101–140  ·  view source on GitHub ↗

Load and normalize a cache entry. Returns: - For .meta.ff: normalized binary bytes (with version prefix) - For .data.ff: raw binary bytes - For .meta.json/.data.json/.deps.json: parsed and normalized dict/list

(cache: MetadataStore, s: str)

Source from the content-addressed store, hash-verified

99
100
101def load(cache: MetadataStore, s: str) -> Any:
102 """Load and normalize a cache entry.
103
104 Returns:
105 - For .meta.ff: normalized binary bytes (with version prefix)
106 - For .data.ff: raw binary bytes
107 - For .meta.json/.data.json/.deps.json: parsed and normalized dict/list
108 """
109 data = cache.read(s)
110 if s.endswith(".meta.ff"):
111 version_prefix = data[:2]
112 buf = ReadBuffer(data[2:])
113 meta = CacheMeta.read(buf, data_file="")
114 if meta is None:
115 # Can't deserialize (e.g. different mypy version). Fall back to
116 # raw bytes -- we lose mtime normalization but the diff stays correct.
117 return data
118 normalize_meta(meta)
119 return serialize_meta_ff(meta, version_prefix)
120 if s.endswith(".meta_ex.ff"):
121 buf = ReadBuffer(data)
122 meta = CacheMetaEx.read(buf)
123 if meta is None:
124 # Can't deserialize. Fall back to raw bytes as above
125 return data
126 meta.dependencies.sort()
127 meta.suppressed.sort()
128 outbuf = WriteBuffer()
129 meta.write(outbuf)
130 return outbuf.getvalue()
131 if s.endswith(".data.ff"):
132 return data
133 obj = json_loads(data)
134 if s.endswith(".meta.json"):
135 normalize_json_meta(obj)
136 if s.endswith(".deps.json"):
137 # For deps files, sort the deps to avoid spurious mismatches
138 for v in obj.values():
139 v.sort()
140 return obj
141
142
143def encode_for_diff(s: str, obj: object) -> str:

Callers 1

mainFunction · 0.85

Calls 9

json_loadsFunction · 0.90
normalize_metaFunction · 0.85
serialize_meta_ffFunction · 0.85
normalize_json_metaFunction · 0.85
sortMethod · 0.80
valuesMethod · 0.80
readMethod · 0.45
endswithMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…