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

Function assert_modules_same

mypyc/test/test_serialization.py:72–94  ·  view source on GitHub ↗

Assert that two module IRs are the same (*). * Or rather, as much as we care about preserving across serialization. We drop the actual IR bodies of functions but try to preserve everything else.

(ir1: ModuleIR, ir2: ModuleIR)

Source from the content-addressed store, hash-verified

70
71
72def assert_modules_same(ir1: ModuleIR, ir2: ModuleIR) -> None:
73 """Assert that two module IRs are the same (*).
74
75 * Or rather, as much as we care about preserving across
76 serialization. We drop the actual IR bodies of functions but try
77 to preserve everything else.
78 """
79 assert ir1.fullname == ir2.fullname
80
81 assert ir1.imports == ir2.imports
82
83 for cls1, cls2 in zip(ir1.classes, ir2.classes):
84 assert_blobs_same(get_dict(cls1), get_dict(cls2), (ir1.fullname, cls1.fullname))
85
86 for fn1, fn2 in zip(ir1.functions, ir2.functions):
87 assert_blobs_same(
88 get_function_dict(fn1), get_function_dict(fn2), (ir1.fullname, fn1.fullname)
89 )
90 assert_blobs_same(get_dict(fn1.decl), get_dict(fn2.decl), (ir1.fullname, fn1.fullname))
91
92 assert_blobs_same(ir1.final_names, ir2.final_names, (ir1.fullname, "final_names"))
93
94 assert ir1.dependencies == ir2.dependencies
95
96
97def check_serialization_roundtrip(irs: dict[str, ModuleIR]) -> None:

Callers 1

Calls 4

zipFunction · 0.85
assert_blobs_sameFunction · 0.85
get_dictFunction · 0.85
get_function_dictFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…