rich.traceback¶
-
class
rich.traceback.
Traceback
(trace: Optional[rich.traceback.Trace] = None, width: Optional[int] = 100, extra_lines: int = 3, theme: Optional[str] = None, word_wrap: bool = False, show_locals: bool = False, indent_guides: bool = True, locals_max_length: int = 10, locals_max_string: int = 80)[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.
-
classmethod
extract
(exc_type: Type[BaseException], exc_value: BaseException, traceback: Optional[traceback], show_locals: bool = False, locals_max_length: int = 10, locals_max_string: int = 80) → rich.traceback.Trace[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.
- Returns
A Trace instance which you can use to construct a Traceback.
- Return type
Trace
-
classmethod
from_exception
(exc_type: Type, exc_value: BaseException, traceback: Optional[traceback], width: Optional[int] = 100, extra_lines: int = 3, theme: Optional[str] = None, word_wrap: bool = False, show_locals: bool = False, indent_guides: bool = True, locals_max_length: int = 10, locals_max_string: int = 80) → rich.traceback.Traceback[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.
- Returns
A Traceback instance that may be printed.
- Return type
-
rich.traceback.
install
(*, console: Optional[rich.console.Console] = None, width: Optional[int] = 100, extra_lines: int = 3, theme: Optional[str] = None, word_wrap: bool = False, show_locals: bool = False, indent_guides: bool = True) → Callable[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.
indent_guides (bool, optional) – Enable indent guides in code and locals. Defaults to True.
- Returns
The previous exception handler that was replaced.
- Return type
Callable