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

Class Traceback

rich/traceback.py:262–895  ·  view source on GitHub ↗

A Console renderable that renders a traceback. Args: 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.

Source from the content-addressed store, hash-verified

260
261
262class Traceback:
263 """A Console renderable that renders a traceback.
264
265 Args:
266 trace (Trace, optional): A `Trace` object produced from `extract`. Defaults to None, which uses
267 the last exception.
268 width (Optional[int], optional): Number of characters used to traceback. Defaults to 100.
269 code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.
270 extra_lines (int, optional): Additional lines of code to render. Defaults to 3.
271 theme (str, optional): Override pygments theme used in traceback.
272 word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
273 show_locals (bool, optional): Enable display of local variables. Defaults to False.
274 indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
275 locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
276 Defaults to 10.
277 locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
278 locals_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
279 locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
280 locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
281 locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
282 suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
283 max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.
284
285 """
286
287 LEXERS = {
288 "": "text",
289 ".py": "python",
290 ".pxd": "cython",
291 ".pyx": "cython",
292 ".pxi": "pyrex",
293 }
294
295 def __init__(
296 self,
297 trace: Optional[Trace] = None,
298 *,
299 width: Optional[int] = 100,
300 code_width: Optional[int] = 88,
301 extra_lines: int = 3,
302 theme: Optional[str] = None,
303 word_wrap: bool = False,
304 show_locals: bool = False,
305 locals_max_length: int = LOCALS_MAX_LENGTH,
306 locals_max_string: int = LOCALS_MAX_STRING,
307 locals_max_depth: Optional[int] = None,
308 locals_hide_dunder: bool = True,
309 locals_hide_sunder: bool = False,
310 locals_overlow: Optional[OverflowMethod] = None,
311 indent_guides: bool = True,
312 suppress: Iterable[Union[str, ModuleType]] = (),
313 max_frames: int = 100,
314 ):
315 if trace is None:
316 exc_type, exc_value, traceback = sys.exc_info()
317 if exc_type is None or exc_value is None or traceback is None:
318 raise ValueError(
319 "Value for 'trace' required if not called in except: block"

Callers 8

test_captureFunction · 0.90
test_no_exceptionFunction · 0.90
get_exceptionFunction · 0.90
test_suppressFunction · 0.90
test_notesFunction · 0.90
print_exceptionMethod · 0.85

Calls

no outgoing calls

Tested by 7

test_captureFunction · 0.72
test_no_exceptionFunction · 0.72
get_exceptionFunction · 0.72
test_suppressFunction · 0.72
test_notesFunction · 0.72