@@ -297,8 +297,7 @@ def dict_diff(dold, dnew, indent=0):
297
297
typical use -- log difference for hashed_inputs
298
298
"""
299
299
try :
300
- dnew = dict (dnew )
301
- dold = dict (dold )
300
+ dnew , dold = dict (dnew ), dict (dold )
302
301
except Exception :
303
302
return textwrap_indent (
304
303
f"""\
@@ -332,18 +331,21 @@ def _shorten(value):
332
331
return tuple (list (value [:2 ]) + ["..." ] + list (value [- 2 :]))
333
332
return value
334
333
334
+ def _uniformize (val ):
335
+ if isinstance (val , dict ):
336
+ return {k : _uniformize (v ) for k , v in val .items ()}
337
+ if isinstance (val , (list , tuple )):
338
+ return tuple (_uniformize (el ) for el in val )
339
+ return val
340
+
335
341
# Values in common keys would differ quite often,
336
342
# so we need to join the messages together
337
343
for k in new_keys .intersection (old_keys ):
338
- new = dnew [k ]
339
- old = dold [k ]
340
344
# Reading from JSON produces lists, but internally we typically
341
345
# use tuples. At this point these dictionary values can be
342
346
# immutable (and therefore the preference for tuple).
343
- if isinstance (dnew [k ], (list , tuple )):
344
- new = tuple ([tuple (el ) if isinstance (el , list ) else el for el in dnew [k ]])
345
- if isinstance (dnew [k ], (list , tuple )):
346
- old = tuple ([tuple (el ) if isinstance (el , list ) else el for el in dold [k ]])
347
+ new = _uniformize (dnew [k ])
348
+ old = _uniformize (dold [k ])
347
349
348
350
if new != old :
349
351
diff += [" * %s: %r != %r" % (k , _shorten (new ), _shorten (old ))]
0 commit comments