MCPcopy Index your code
hub / github.com/python/cpython / diff_dict

Function diff_dict

Lib/test/test_getpath.py:1224–1243  ·  view source on GitHub ↗
(before, after, prefix="global")

Source from the content-addressed store, hash-verified

1222
1223
1224def diff_dict(before, after, prefix="global"):
1225 diff = []
1226 for k in sorted(before):
1227 if k[:2] == "__":
1228 continue
1229 if k == "config":
1230 diff_dict(before[k], after[k], prefix="config")
1231 continue
1232 if k in after and after[k] != before[k]:
1233 diff.append((k, before[k], after[k]))
1234 if not diff:
1235 return
1236 max_k = max(len(k) for k, _, _ in diff)
1237 indent = " " * (len(prefix) + 1 + max_k)
1238 if verbose:
1239 for k, b, a in diff:
1240 if b:
1241 print("{}.{} -{!r}\n{} +{!r}".format(prefix, k.ljust(max_k), b, indent, a))
1242 else:
1243 print("{}.{} +{!r}".format(prefix, k.ljust(max_k), a))
1244
1245
1246def dump_dict(before, after, prefix="global"):

Callers 1

getpathFunction · 0.85

Calls 3

appendMethod · 0.45
formatMethod · 0.45
ljustMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…