Skip to content

Commit 90e2130

Browse files
oestebaneffigies
andcommitted
enh: apply comments from review
Co-authored-by: Chris Markiewicz <[email protected]>
1 parent c8c7682 commit 90e2130

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

nipype/utils/misc.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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,18 +331,21 @@ 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):
338-
new = dnew[k]
339-
old = dold[k]
340344
# Reading from JSON produces lists, but internally we typically
341345
# use tuples. At this point these dictionary values can be
342346
# 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])
347349

348350
if new != old:
349351
diff += [" * %s: %r != %r" % (k, _shorten(new), _shorten(old))]

0 commit comments

Comments
 (0)