Initial blank line of multiline output #10138

Closed
kwankyu opened this Issue Jan 8, 2017 · 4 comments

Projects

None yet

2 participants

@kwankyu
kwankyu commented Jan 8, 2017

The following is normal.

In [1]: class Foo(object):
   ...: 
   ...:     def __repr__(self):
   ...:         return "foo"
   ...: 
   ...: 
   ...: class Bar(object):
   ...: 
   ...:     def __repr__(self):
   ...:         return "bar\nbar"
   ...:     

In [2]: Foo()
Out[2]: foo

In [3]: Bar()
Out[3]: 
bar
bar

But in Sage that uses IPython, the initial blank line for multiline output is just redundant.

sage: class Foo(object):
....: 
....:     def __repr__(self):
....:         return "foo"
....: 
....: 
....: class Bar(object):
....: 
....:     def __repr__(self):
....:         return "bar\nbar"
....:     
sage: 
sage: Foo()
foo
sage: Bar()

bar
bar

I am not sure if this is a bug of IPython or of Sage. I would appreciate comments by anyone who knows better.

@kwankyu
kwankyu commented Jan 8, 2017

I investigated this issue a bit more. The method write_output_prompt in the class RichPromptDisplayHook sets the attribute prompt_end_newline to true when the output prompt ends explicitly with \n. In Sage, the output prompt is just empty string. I think that in this case too, the attribute prompt_end_newline should be set true. Thus we can consider that the current erroneous behavior in Sage is caused by this bug in IPython.

@takluyver
Member

Sounds reasonable. Do you want to make a PR?

@kwankyu
kwankyu commented Jan 9, 2017

Actually I am not familiar with IPython code and collaborative development in Github. So it would take some time for me to make a pull request of a patch. If you or any one can do this easily, then I would be happy to concede.

@takluyver takluyver added a commit to takluyver/ipython that referenced this issue Jan 9, 2017
@takluyver takluyver Empty prompt effectively ends with newline
Closes gh-10138
4c6e63d
@takluyver
Member

OK, see #10146

@takluyver takluyver closed this in #10146 Jan 12, 2017
@takluyver takluyver added a commit that referenced this issue Jan 12, 2017
@takluyver @takluyver takluyver + takluyver Backport PR #10146: Empty prompt effectively ends with newline
Closes gh-10138

Signed-off-by: Thomas Kluyver <thomas@kluyver.me.uk>
9a14f98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment