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

Method dump_types

mypy/test/testmerge.py:205–232  ·  view source on GitHub ↗
(
        self, modules: dict[str, MypyFile], manager: FineGrainedBuildManager
    )

Source from the content-addressed store, hash-verified

203 return s.splitlines()
204
205 def dump_types(
206 self, modules: dict[str, MypyFile], manager: FineGrainedBuildManager
207 ) -> list[str]:
208 a = []
209 # To make the results repeatable, we try to generate unique and
210 # deterministic sort keys.
211 for module_id in sorted(modules):
212 all_types = manager.manager.all_types
213 # Compute a module type map from the global type map
214 tree = manager.graph[module_id].tree
215 assert tree is not None
216 type_map = {
217 node: all_types[node] for node in get_subexpressions(tree) if node in all_types
218 }
219 if type_map:
220 a.append(f"## {module_id}")
221 for expr in sorted(
222 type_map,
223 key=lambda n: (
224 n.line,
225 short_type(n),
226 n.str_with_options(self.str_conv.options)
227 + type_map[n].accept(self.type_str_conv),
228 ),
229 ):
230 typ = type_map[expr]
231 a.append(f"{short_type(expr)}:{expr.line}: {self.format_type(typ)}")
232 return a
233
234 def format_type(self, typ: Type) -> str:
235 return typ.accept(self.type_str_conv)

Callers 1

dumpMethod · 0.95

Calls 7

format_typeMethod · 0.95
get_subexpressionsFunction · 0.90
short_typeFunction · 0.90
sortedFunction · 0.85
appendMethod · 0.80
str_with_optionsMethod · 0.45
acceptMethod · 0.45

Tested by

no test coverage detected