Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4e12b3

Browse files
authored
Start multi-line __repr__s on their own line
Fixes gh-12098
1 parent a6082c6 commit a4e12b3

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

IPython/lib/pretty.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,11 @@ def _repr_pprint(obj, p, cycle):
687687
"""A pprint that just redirects to the normal repr function."""
688688
# Find newlines and replace them with p.break_()
689689
output = repr(obj)
690-
for idx,output_line in enumerate(output.splitlines()):
690+
lines = output.splitlines()
691+
# insert a leading newline for multi-line objects that are indented
692+
if len(lines) > 1 and p.indentation != p.output_width:
693+
p.break_()
694+
for idx, output_line in enumerate(lines):
691695
if idx:
692696
p.break_()
693697
p.text(output_line)

0 commit comments

Comments
 (0)