$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"
VERSION_ID="13"
VERSION="13 (trixie)"
VERSION_CODENAME=trixie
DEBIAN_VERSION_FULL=13.4
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Terminal is iTerm2 3.6.11 on Mac.
$ python -m rich.diagnose
╭─────────────────────── <class 'rich.console.Console'> ───────────────────────╮
│ A high level console interface. │
│ │
│ ╭──────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=80 ColorSystem.EIGHT_BIT> │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = '256' │
│ encoding = 'utf-8' │
│ file = <_io.TextIOWrapper name='<stdout>' mode='w' │
│ encoding='utf-8'> │
│ height = 25 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = True │
│ is_jupyter = False │
│ is_terminal = True │
│ legacy_windows = False │
│ no_color = False │
│ options = ConsoleOptions( │
│ size=ConsoleDimensions(width=80, height=25), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=80, │
│ is_terminal=True, │
│ encoding='utf-8', │
│ max_height=25, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=80, height=25) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 80 │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available. │
│ │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│ │
│ truecolor = False │
│ vt = False │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ { │
│ 'CLICOLOR': None, │
│ 'COLORTERM': None, │
│ 'COLUMNS': None, │
│ 'JPY_PARENT_PID': None, │
│ 'JUPYTER_COLUMNS': None, │
│ 'JUPYTER_LINES': None, │
│ 'LINES': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': None, │
│ 'TERM': 'xterm-256color', │
│ 'TTY_COMPATIBLE': None, │
│ 'TTY_INTERACTIVE': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Linux"
$ pip freeze | fgrep rich
rich==15.0.0
Describe the bug
I have some code that I was debugging and was confused by the appearance of attributes called
awehoi234_wdfjwljet234_234wdfoijsdfmmnxpi492and_fields. This was pretty hard to debug. It turned out that these are both added byrich.awehoi234_wdfjwljet234_234wdfoijsdfmmnxpi492is used to test objects for auto-vivifying attributes. If the test succeeds (e.g., theBoxclass), the new attribute is left on the object._fieldsis used to test if an object appears to be anamedtuple. The comment asserts that “[i]t is possible to craft an object that passes this check and isn't a namedtuple, but there is only a minuscule chance of this happening unintentionally.” I don’t think that’s true; any object that auto-vivifies attributes will pass the check.In my view, a library designed for debugging output (which
richis quite good at) should do its best to not modify the objects it is displaying, and if it does modify them, to be as obvious as practical about where the modifications came from.I would suggest:
Because the sentinel
awehoi234_wdfjwljet234_234wdfoijsdfmmnxpi492is controlled byrich, change it to something that makes its provenance clear, say_rich_fake_attribute_test.Remove the sentinel attribute if it’s successfully created, e.g. with
delattr().Test for the presence of
_fieldsin a way that avoids false positives on auto-vivifying objects, e.g. with__getattribute__()instead ofgetattr().Thanks for
rich, it’s been very helpful.Platform
Click to expand
Virtual machine accessed by SSH:
Terminal is iTerm2 3.6.11 on Mac.