Opened 5 years ago

Closed 4 years ago

#22158 closed defect (wontfix)

Extraneous line for multiline output in Sage command line

Reported by: klee Owned by:
Priority: minor Milestone: sage-duplicate/invalid/wontfix
Component: user interface Keywords:
Cc: stakemori, tscrim Merged in:
Authors: Reviewers: Travis Scrimshaw
Report Upstream: Fixed upstream, but not in a stable release. Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

To reproduce it, run Sage in the terminal and evaluate the following code. Extra blank lines are printed before outputs as below:

class Foo(object):

    def __repr__(self):
        return "foo"


class Bar(object):

    def __repr__(self):
        return "bar\nbar"


sage: identity_matrix(QQ, 2)

[1 0]
[0 1]
sage: Foo()
foo
sage: Bar()

bar
bar

This was first discussed in https://groups.google.com/forum/#!topic/sage-devel/AYYaUb_9kjw

Change History (15)

comment:1 Changed 5 years ago by klee

The related upstream discussion is in https://github.com/ipython/ipython/issues/10138

comment:2 Changed 5 years ago by stakemori

  • Cc stakemori added

comment:3 follow-up: Changed 5 years ago by stakemori

Thank you. I will try to make a patch this weekend.

comment:4 in reply to: ↑ 3 ; follow-up: Changed 5 years ago by klee

Replying to stakemori:

Thank you. I will try to make a patch this weekend.

Did you see the comment posted in the upstream discussion? We may think that the bug is in IPython than in Sage. So we need a patch for IPython. You may submit a pull request of the patch to IPython Github repo.

comment:5 Changed 5 years ago by klee

  • Report Upstream changed from Reported upstream. No feedback yet. to Fixed upstream, but not in a stable release.

comment:6 in reply to: ↑ 4 Changed 5 years ago by stakemori

Replying to klee:

I saw the pull request. This has been fixed in IPython. But I think this can be fixed immediately in Sage (how long will it take before the fix will be merged into Sage?). Right now I have a fever, so I avoid coding.

comment:7 Changed 5 years ago by klee

It will take some time for the fix in the upstream eventually to get into a release of Sage. For the impatient, copy and paste the following to replace the code for write_output_prompt method in sage/local/lib/python/site-packages/IPython/terminal.

    def write_output_prompt(self):
        sys.stdout.write(self.shell.separate_out)
        # If we're not displaying a prompt, it effectively ends with a newline,
        # because the output will be left-aligned.
        self.prompt_end_newline = True

        if self.do_full_cache:
            tokens = self.shell.prompts.out_prompt_tokens()
            prompt_txt = ''.join(s for t, s in tokens)
            if prompt_txt and not prompt_txt.endswith('\n'):
                # Ask for a newline before multiline output
                self.prompt_end_newline = False

            if self.shell.pt_cli:
                self.shell.pt_cli.print_tokens(tokens)
            else:
                sys.stdout.write(prompt_txt) 

comment:8 Changed 5 years ago by stakemori

For the impatient, copy and paste the following to replace the code for write_output_prompt method in sage/local/lib/python/site-packages/IPython/terminal.

The method write_output_prompt of the class RichPromptDisplayHook in $SAGE_ROOT/local/lib/python/site-packages/IPython/terminal/prompts.py more precisely.

comment:9 follow-up: Changed 5 years ago by tscrim

  • Cc tscrim added

We can just patch Sage's IPython in the meantime. This is the fastest fix, as we have to wait for the next version of IPython with the PR included.

I doubt Volker will let this ticket get into the 7.5 release though. :/

comment:10 in reply to: ↑ 9 Changed 5 years ago by jdemeyer

Replying to tscrim:

as we have to wait for the next version of IPython with the PR included.

That would be a pity for such an important major bug like this one ;-)

comment:11 Changed 5 years ago by stakemori

I made a patch for this problem. I think the attribute prompt_end_newline should be always true. https://gist.github.com/stakemori/68f42ba2f9ac6f6d581e9525c1c41e07

comment:12 Changed 5 years ago by klee

Your patch will be redundant once the next release of IPython is incorporated to Sage. Note that the upstream patch was back ported to the current release, which means, I guess, that the fixed IPython would be available in Sage sooner than usual.

Your patch can be used as an (alternative) temporary measure to fix the issue, but should not be merged to Sage.

comment:13 Changed 4 years ago by klee

  • Status changed from new to needs_review

As Sage's IPython was updated to version 5.5, this issue is now fixed. Nice!

comment:14 Changed 4 years ago by tscrim

  • Milestone changed from sage-7.5 to sage-duplicate/invalid/wontfix
  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

Indeed!

comment:15 Changed 4 years ago by vdelecroix

  • Resolution set to wontfix
  • Status changed from positive_review to closed

closing positively reviewed duplicates

Note: See TracTickets for help on using tickets.