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] Traceback.from_exception ignores locals_max_length and locals_max_string arguments #2649

Closed
giladbarnea opened this issue Nov 15, 2022 · 1 comment · Fixed by #2657
Closed

Comments

@giladbarnea
Copy link

giladbarnea commented Nov 15, 2022

Describe the bug

Specifying locals_max_length and locals_max_string when using Traceback.from_exception has no effect; the defaults LOCALS_MAX_LENGTH and LOCALS_MAX_STRING are used instead.


I made a fix: #2650


Reproduce

from rich import get_console
from rich.traceback import Traceback
import string

console = get_console()


def fails():
    d = { "a": string.digits + string.ascii_lowercase + string.ascii_uppercase + string.punctuation }
    1 / 0


def main():
    try:
        fails()
    except Exception as e:
        traceback = Traceback.from_exception(
            type(e),
            e,
            e.__traceback__,
            width=console.width,
            show_locals=True,
            locals_max_length=1000,
            locals_max_string=1000,
        )
        console.print(traceback)


if __name__ == "__main__":
    main()

image

Workaround

from rich import get_console
from rich.traceback import Traceback
import string

console = get_console()


def fails():
    d = { "a": string.digits + string.ascii_lowercase + string.ascii_uppercase + string.punctuation }
    1 / 0


def main():
    try:
        fails()
    except Exception as e:
        trace = Traceback.extract(
            type(e),
            e,
            e.__traceback__,
            show_locals=True,
            locals_max_length=1000,
            locals_max_string=1000,
        )
        traceback = Traceback(trace, width=console.width)
        console.print(traceback)


if __name__ == "__main__":
    main()

image

Platform

Click to expand

MacOS Monterey 14" 2021 M1 Pro
Version 12.6
Terminal: kitty 0.25.0

rich==13.0.0  # pip freeze | grep rich
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=158 None>                                                     │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = None                                                          │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 39                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = False                                                         │
│       is_jupyter = False                                                         │
│      is_terminal = False                                                         │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=158, height=39),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=158,                                            │
│                        is_terminal=False,                                        │
│                        encoding='utf-8',                                         │
│                        max_height=39,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=158, height=39)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 158                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-kitty',         │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Darwin"
@github-actions
Copy link

github-actions bot commented Dec 4, 2022

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

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

Successfully merging a pull request may close this issue.

1 participant