MCPcopy
hub / github.com/Textualize/rich / install

Function install

rich/traceback.py:84–218  ·  view source on GitHub ↗

Install a rich traceback handler. Once installed, any tracebacks will be printed with syntax highlighting and rich formatting. Args: console (Optional[Console], optional): Console to write exception to. Default uses internal Console instance. width (Optional[int], optional

(
    *,
    console: Optional[Console] = None,
    width: Optional[int] = 100,
    code_width: Optional[int] = 88,
    extra_lines: int = 3,
    theme: Optional[str] = None,
    word_wrap: bool = False,
    show_locals: bool = False,
    locals_max_length: int = LOCALS_MAX_LENGTH,
    locals_max_string: int = LOCALS_MAX_STRING,
    locals_max_depth: Optional[int] = None,
    locals_hide_dunder: bool = True,
    locals_hide_sunder: Optional[bool] = None,
    locals_overflow: Optional[OverflowMethod] = None,
    indent_guides: bool = True,
    suppress: Iterable[Union[str, ModuleType]] = (),
    max_frames: int = 100,
)

Source from the content-addressed store, hash-verified

82
83
84def install(
85 *,
86 console: Optional[Console] = None,
87 width: Optional[int] = 100,
88 code_width: Optional[int] = 88,
89 extra_lines: int = 3,
90 theme: Optional[str] = None,
91 word_wrap: bool = False,
92 show_locals: bool = False,
93 locals_max_length: int = LOCALS_MAX_LENGTH,
94 locals_max_string: int = LOCALS_MAX_STRING,
95 locals_max_depth: Optional[int] = None,
96 locals_hide_dunder: bool = True,
97 locals_hide_sunder: Optional[bool] = None,
98 locals_overflow: Optional[OverflowMethod] = None,
99 indent_guides: bool = True,
100 suppress: Iterable[Union[str, ModuleType]] = (),
101 max_frames: int = 100,
102) -> Callable[[Type[BaseException], BaseException, Optional[TracebackType]], Any]:
103 """Install a rich traceback handler.
104
105 Once installed, any tracebacks will be printed with syntax highlighting and rich formatting.
106
107
108 Args:
109 console (Optional[Console], optional): Console to write exception to. Default uses internal Console instance.
110 width (Optional[int], optional): Width (in characters) of traceback. Defaults to 100.
111 code_width (Optional[int], optional): Code width (in characters) of traceback. Defaults to 88.
112 extra_lines (int, optional): Extra lines of code. Defaults to 3.
113 theme (Optional[str], optional): Pygments theme to use in traceback. Defaults to ``None`` which will pick
114 a theme appropriate for the platform.
115 word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
116 show_locals (bool, optional): Enable display of local variables. Defaults to False.
117 locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
118 Defaults to 10.
119 locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
120 locals_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
121 locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
122 locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
123 locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
124 indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
125 suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
126
127 Returns:
128 Callable: The previous exception handler that was replaced.
129
130 """
131 traceback_console = Console(stderr=True) if console is None else console
132
133 locals_hide_sunder = (
134 True
135 if (traceback_console.is_jupyter and locals_hide_sunder is None)
136 else locals_hide_sunder
137 )
138
139 def excepthook(
140 type_: Type[BaseException],
141 value: BaseException,

Callers 3

test_handlerFunction · 0.90
suppress.pyFile · 0.90
traceback.pyFile · 0.70

Calls 2

ConsoleClass · 0.85
ipy_excepthook_closureFunction · 0.85

Tested by 1

test_handlerFunction · 0.72