Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#2793·rich

[BUG] JupyterMixin adds spurious trailing newline

Author: NickCrewsCreated Feb 2, 2023Updated Aug 28, 2026
LabelsNeeds triage
  • I've checked docs and closed issues for possible solutions.
  • I can't find my issue in the FAQ.

Describe the bug

See the workaround we had to do at https://github.com/ibis-project/ibis/commit/ee6d58a5a9ac10dff19c87afe6b482bed83d5b41

Proof of the problem is:

from rich.jupyter import JupyterMixin

class _FixedTextJupyterMixin(JupyterMixin):
    """JupyterMixin adds a spurious newline to text, this fixes the issue."""

    def _repr_mimebundle_(self, *args, **kwargs):
        bundle = super()._repr_mimebundle_(*args, **kwargs)
        assert bundle["text/plain"].endswith("\n")
        bundle["text/plain"] = bundle["text/plain"].rstrip()
        return bundle

class MyClass(_FixedTextJupyterMixin):
    def __rich_console__(self, console, options):
        return ["hello"]

# Run this in jupyter, the assert above does not trigger
MyClass()

cc @cpcloud

Source: Textualize/rich

View original on GitHubView discussion on GitHub