@@ -18,28 +18,29 @@ def format_value(value, depth):
1818 return str (value )
1919
2020
21-
2221def format_stylish (diff , depth = 0 ):
2322 indent = " " * (depth * 4 )
2423 lines = ["{" ]
2524
2625 for key , info in sorted (diff .items ()):
27- status = info ["status" ]
28- value = format_value (info .get ("value" ), depth + 1 )
29- old_value = format_value (info .get ("old_value" ), depth + 1 )
30- new_value = format_value (info .get ("new_value" ), depth + 1 )
26+ status = info .get ("status" )
3127
3228 if status == "nested" :
33- children = format_stylish (info [ "children" ] , depth + 1 )
29+ children = format_stylish (info . get ( "children" , {}) , depth + 1 )
3430 lines .append (f"{ indent } { key } : { children } " )
3531 elif status == "added" :
32+ value = format_value (info .get ("value" ), depth + 1 )
3633 lines .append (f"{ indent } + { key } : { value } " )
3734 elif status == "removed" :
35+ value = format_value (info .get ("value" ), depth + 1 )
3836 lines .append (f"{ indent } - { key } : { value } " )
3937 elif status == "modified" :
38+ old_value = format_value (info .get ("old_value" ), depth + 1 )
39+ new_value = format_value (info .get ("new_value" ), depth + 1 )
4040 lines .append (f"{ indent } - { key } : { old_value } " )
4141 lines .append (f"{ indent } + { key } : { new_value } " )
4242 else : # unchanged
43+ value = format_value (info .get ("value" ), depth + 1 )
4344 lines .append (f"{ indent } { key } : { value } " )
4445
4546 lines .append (f"{ indent } }}" )
0 commit comments