2121#
2222
2323#
24- # Copyright (c) 2009, 2024 , Oracle and/or its affiliates.
24+ # Copyright (c) 2009, 2025 , Oracle and/or its affiliates.
2525#
2626
2727try :
@@ -317,29 +317,28 @@ def conditional_print(s, a):
317317 elif not old :
318318 different |= conditional_print ("+" , new )
319319 else :
320- s = []
320+ output = []
321321
322322 if not onlyattrs :
323- if (hasattr (old , "hash" ) and
324- "hash" not in ignoreattrs ):
323+ if hasattr (old , "hash" ) and "hash" not in ignoreattrs :
325324 if old .hash != new .hash :
326- s .append (" - {0}" .format (old .hash ))
327- s .append (" + {0}" .format (new .hash ))
328- attrdiffs = (set (new .differences (old )) -
329- ignoreattrs )
330- attrsames = sorted ( list (set (list (old .attrs .keys ()) +
331- list (new .attrs .keys ())) -
332- set (new .differences (old ))))
325+ output .append (f" - { old .hash } " )
326+ output .append (f" + { new .hash } " )
327+ attrdiffs = set (new .differences (old )) - ignoreattrs
333328 else :
334329 if hasattr (old , "hash" ) and "hash" in onlyattrs :
335330 if old .hash != new .hash :
336- s .append (" - {0}" .format (old .hash ))
337- s .append (" + {0}" .format (new .hash ))
338- attrdiffs = (set (new .differences (old )) &
339- onlyattrs )
340- attrsames = sorted (list (set (list (old .attrs .keys ()) +
341- list (new .attrs .keys ())) -
342- set (new .differences (old ))))
331+ output .append (f" - { old .hash } " )
332+ output .append (f" + { new .hash } " )
333+ attrdiffs = set (new .differences (old )) & onlyattrs
334+
335+ # sort attributes by name and put the key attribute first
336+ attrsames = sorted (
337+ set (old .attrs )
338+ .union (new .attrs )
339+ .difference (new .differences (old )),
340+ key = lambda val : "" if val == old .key_attr else val
341+ )
343342
344343 for a in sorted (attrdiffs ):
345344 if a in old .attrs and a in new .attrs and \
@@ -350,25 +349,21 @@ def conditional_print(s, a):
350349 else :
351350 elide_set = set ()
352351 if a in old .attrs :
353- diff_str = attrval (old .attrs , a ,
354- elide_iter = elide_set )
352+ diff_str = attrval (old .attrs , a , elide_iter = elide_set )
355353 if diff_str :
356- s .append (" - {0}" . format ( diff_str ) )
354+ output .append (f " - { diff_str } " )
357355 if a in new .attrs :
358- diff_str = attrval (new .attrs , a ,
359- elide_iter = elide_set )
356+ diff_str = attrval (new .attrs , a , elide_iter = elide_set )
360357 if diff_str :
361- s .append (" + {0}" .format (diff_str ))
362- # print out part of action that is the same
363- if s :
358+ output .append (f" + { diff_str } " )
359+ if output :
364360 different = True
365- print ("{0} {1} {2}" .format (old .name ,
366- attrval (old .attrs , old .key_attr ),
367- " " .join (("{0}" .format (attrval (old .attrs , v ))
368- for v in attrsames if v != old .key_attr ))))
369361
370- for l in s :
371- print (l )
362+ # print out part of action that is the same
363+ attrs = ' ' .join (attrval (old .attrs , val ) for val in attrsames )
364+ print (f"{ old .name } { attrs } " )
365+ # and then all the differences
366+ print ("\n " .join (output ))
372367
373368 return int (different )
374369
0 commit comments