Skip to content

Commit 08ba4f5

Browse files
committed
step9
1 parent f012470 commit 08ba4f5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

gendiff/formaters/stylish.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,29 @@ def format_value(value, depth):
1818
return str(value)
1919

2020

21-
2221
def 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}}}")

gendiff/parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ def args_parser():
1515
)
1616
args = parser.parse_args()
1717

18-
diff = generate_diff(args.first_file, args.second_file,
18+
return generate_diff(args.first_file, args.second_file,
1919
format_name=args.format)
20-
print(diff)

0 commit comments

Comments
 (0)