@@ -297,8 +297,7 @@ def dict_diff(dold, dnew, indent=0):
297297 typical use -- log difference for hashed_inputs
298298 """
299299 try :
300- dnew = dict (dnew )
301- dold = dict (dold )
300+ dnew , dold = dict (dnew ), dict (dold )
302301 except Exception :
303302 return textwrap_indent (
304303 f"""\
@@ -332,6 +331,13 @@ def _shorten(value):
332331 return tuple (list (value [:2 ]) + ["..." ] + list (value [- 2 :]))
333332 return value
334333
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+
335341 # Values in common keys would differ quite often,
336342 # so we need to join the messages together
337343 for k in new_keys .intersection (old_keys ):
@@ -340,10 +346,8 @@ def _shorten(value):
340346 # Reading from JSON produces lists, but internally we typically
341347 # use tuples. At this point these dictionary values can be
342348 # 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 ]])
349+ new = _uniformize (dnew [k ])
350+ old = _uniformize (dold [k ])
347351
348352 if new != old :
349353 diff += [" * %s: %r != %r" % (k , _shorten (new ), _shorten (old ))]
0 commit comments