Skip to content
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

[BUG] Rich.pretty breaks IPython built-in %pprint #1611

Closed
aroberge opened this issue Oct 19, 2021 · 3 comments
Closed

[BUG] Rich.pretty breaks IPython built-in %pprint #1611

aroberge opened this issue Oct 19, 2021 · 3 comments

Comments

@aroberge
Copy link

Describe the bug
When using rich.pretty, the builtin %pprint command results in a traceback

%pprint is intended to toggle on and off the pretty printing, something which is not supported by Rich in general.

To Reproduce

In [1]: from rich import pretty

In [2]: pretty.install()

In [3]: %pprint
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

... (lines removed)
    306         """Toggle pretty printing on/off."""
    307         ptformatter = self.shell.display_formatter.formatters['text/plain']
--> 308         ptformatter.pprint = bool(1 - ptformatter.pprint)
    309         print('Pretty printing has been turned',
    310               ['OFF','ON'][ptformatter.pprint])

AttributeError: 'BaseFormatter' object has no attribute 'pprint'

Possible solutions

  • Ideal solution: rich.pretty supports %pprint
  • Next best solution: Attempting to use %pprint with rich.pretty results in a message indicating that this is not supported
  • Minimal solution: A note is added in the documentation about this feature not being supported and a message is printed
    when pretty is installed inside IPython.

Platform
Windows 10; Windows Terminal

Diagnose
rich==10.12.0
ipython==7.25.0

@aroberge
Copy link
Author

I believe that adding the following would work as a minimal implementation:

from IPython.core.magic import register_line_cell_magic
@register_line_cell_magic
def pprint(_line=None, _cell=None):
    print("%pprint is not supported by Rich.")

@aroberge
Copy link
Author

aroberge commented Nov 6, 2021

Closing as this was taken care of in #1646

@aroberge aroberge closed this as completed Nov 6, 2021
@github-actions
Copy link

github-actions bot commented Nov 6, 2021

Did I solve your problem?

Consider sponsoring the ongoing work on Rich and Textual.

Or buy me a coffee to say thanks.

Will McGugan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant