New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix indentation bug in IPython/lib/pretty.py #1517
Conversation
_PrettyPrinterBase.group() was increasing the indentation twice (once in the call to begin_group() and once in the call to indent()). Fixed by removing the call to indent().
Can you give an example that shows the bug? Also, if possible, a unit test for this would be good. |
Try the following class: class MyList(object):
def __init__(self, content):
self.content = content
def _repr_pretty_(self, p, cycle):
if cycle:
p.text("MyList(...)")
else:
with p.group(3, "MyList(", ")"):
for (i, child) in enumerate(self.content):
if i:
p.text(",")
p.breakable()
p.pretty(child) Without the patch the output is indented six spaces, although the code specifies 3:
With the patch the output is indented 3 spaces:
|
Also here is a test: from IPython.lib import pretty
class MyList(object):
def __init__(self, content):
self.content = content
def _repr_pretty_(self, p, cycle):
if cycle:
p.text("MyList(...)")
else:
with p.group(3, "MyList(", ")"):
for (i, child) in enumerate(self.content):
if i:
p.text(",")
p.breakable()
else:
p.breakable("")
p.pretty(child)
gotoutput = pretty.pretty(MyList(range(30)))
expectedoutput = "MyList(\n" + ",\n".join(" %d" % i for i in range(30)) + ")"
assert gotoutput == expectedoutput However I don't know where I should put the test. |
A new |
OK, I've added the test to the new test_pretty.py file. |
OK, this all looks OK, so I'm going to go ahead and merge it. Thanks, @doerwalter. |
Fix indentation bug in IPython/lib/pretty.py
Fix indentation bug in IPython/lib/pretty.py
_PrettyPrinterBase.group() was increasing the indentation twice
(once in the call to begin_group() and once in the call to indent()).
Fixed by removing the call to indent().