rich.traceback¶
- class rich.traceback.Traceback(trace=None, *, width=100, extra_lines=3, theme=None, word_wrap=False, show_locals=False, locals_max_length=10, locals_max_string=80, locals_hide_dunder=True, locals_hide_sunder=False, indent_guides=True, suppress=(), max_frames=100)[source]¶
A Console renderable that renders a traceback.
- Parameters
trace (Trace, optional) – A Trace object produced from extract. Defaults to None, which uses the last exception.
width (Optional[int], optional) – Number of characters used to traceback. Defaults to 100.
extra_lines (int, optional) – Additional lines of code to render. Defaults to 3.
theme (str, optional) – Override pygments theme used in traceback.
word_wrap (bool, optional) – Enable word wrapping of long lines. Defaults to False.
show_locals (bool, optional) – Enable display of local variables. Defaults to False.
indent_guides (bool, optional) – Enable indent guides in code and locals. Defaults to True.
locals_max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10.
locals_max_string (int, optional) – Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_hide_dunder (bool, optional) – Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional) – Hide locals prefixed with single underscore. Defaults to False.
suppress (Sequence[Union[str, ModuleType]]) – Optional sequence of modules or paths to exclude from traceback.
max_frames (int) – Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.
- classmethod extract(exc_type, exc_value, traceback, *, show_locals=False, locals_max_length=10, locals_max_string=80, locals_hide_dunder=True, locals_hide_sunder=False)[source]¶
Extract traceback information.
- Parameters
exc_type (Type[BaseException]) – Exception type.
exc_value (BaseException) – Exception value.
traceback (TracebackType) – Python Traceback object.
show_locals (bool, optional) – Enable display of local variables. Defaults to False.
locals_max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10.
locals_max_string (int, optional) – Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_hide_dunder (bool, optional) – Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional) – Hide locals prefixed with single underscore. Defaults to False.
- Returns
A Trace instance which you can use to construct a Traceback.
- Return type
Trace
- classmethod from_exception(exc_type, exc_value, traceback, *, width=100, extra_lines=3, theme=None, word_wrap=False, show_locals=False, locals_max_length=10, locals_max_string=80, locals_hide_dunder=True, locals_hide_sunder=False, indent_guides=True, suppress=(), max_frames=100)[source]¶
Create a traceback from exception info
- Parameters
exc_type (Type[BaseException]) – Exception type.
exc_value (BaseException) – Exception value.
traceback (TracebackType) – Python Traceback object.
width (Optional[int], optional) – Number of characters used to traceback. Defaults to 100.
extra_lines (int, optional) – Additional lines of code to render. Defaults to 3.
theme (str, optional) – Override pygments theme used in traceback.
word_wrap (bool, optional) – Enable word wrapping of long lines. Defaults to False.
show_locals (bool, optional) – Enable display of local variables. Defaults to False.
indent_guides (bool, optional) – Enable indent guides in code and locals. Defaults to True.
locals_max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10.
locals_max_string (int, optional) – Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_hide_dunder (bool, optional) – Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional) – Hide locals prefixed with single underscore. Defaults to False.
suppress (Iterable[Union[str, ModuleType]]) – Optional sequence of modules or paths to exclude from traceback.
max_frames (int) – Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.
- Returns
A Traceback instance that may be printed.
- Return type
- rich.traceback.install(*, console=None, width=100, extra_lines=3, theme=None, word_wrap=False, show_locals=False, locals_max_length=10, locals_max_string=80, locals_hide_dunder=True, locals_hide_sunder=None, indent_guides=True, suppress=(), max_frames=100)[source]¶
Install a rich traceback handler.
Once installed, any tracebacks will be printed with syntax highlighting and rich formatting.
- Parameters
console (Optional[Console], optional) – Console to write exception to. Default uses internal Console instance.
width (Optional[int], optional) – Width (in characters) of traceback. Defaults to 100.
extra_lines (int, optional) – Extra lines of code. Defaults to 3.
theme (Optional[str], optional) – Pygments theme to use in traceback. Defaults to
None
which will pick a theme appropriate for the platform.word_wrap (bool, optional) – Enable word wrapping of long lines. Defaults to False.
show_locals (bool, optional) – Enable display of local variables. Defaults to False.
locals_max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10.
locals_max_string (int, optional) – Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_hide_dunder (bool, optional) – Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional) – Hide locals prefixed with single underscore. Defaults to False.
indent_guides (bool, optional) – Enable indent guides in code and locals. Defaults to True.
suppress (Sequence[Union[str, ModuleType]]) – Optional sequence of modules or paths to exclude from traceback.
max_frames (int) –
- Returns
The previous exception handler that was replaced.
- Return type
Callable