Open MicaelJarniac opened 1 year ago
Same thing happens on macOS Ventura 13.4.1 with iTerm2. Doesn't seem like it's platform-dependent but @MicaelJarniac asked me to check :D
I've simplified the example a lot, and came to this:
from rich.pretty import pprint
class A:
def __init__(self, a=None):
self.a = a
def __repr__(self) -> str:
return f"A(a={repr(self.a)}, b=<B>)"
pprint(A())
pprint(A("<"))
pprint(A(">"))
pprint(A("x"))
I suspect the bug is in this line: https://github.com/Textualize/rich/blob/aca9467ec6a482b3bed1ba7d2e3de72271c5f817/rich/highlighter.py#L85
from rich.pretty import pprint
class A:
def __init__(self, a=None):
self.a = a
def __repr__(self) -> str:
return f"A(a={self.a!r}, b=1.23, c=None, d=(1, 2))"
pprint([A("<"), A(">")])
Describe the bug
If there's a
<
(less than) char in the repr of an object, the colors of other components that use<>
break after it.For example, if I have a dataclass or an attrs class with more than one enum attribute, the color of subsequent ones break when pretty printing.
On the terminal:
On Jupyter:
Platform
Click to expand
Operating System: Manjaro Linux KDE Plasma Version: 5.27.5 KDE Frameworks Version: 5.106.0 Qt Version: 5.15.9 Kernel Version: 6.1.31-2-MANJARO (64-bit) Graphics Platform: Wayland Processors: 16 × AMD Ryzen 7 5800H with Radeon Graphics Memory: 13.5 GiB of RAM Graphics Processor: AMD Radeon Graphics Manufacturer: LENOVO Product Name: 82MJ System Version: IdeaPad Gaming 3 15ACH6 Shell: Zsh with Zsh for Humans and Tmux Terminal: VS Code's built-in terminal If you're using Rich in a terminal: ``` python -m rich.diagnose pip freeze | grep rich ````python -m rich.diagnose`
``` ❯ python -m rich.diagnose ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────Report
``` ╭──────────────────────