Important

This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: core.tbtools

2 Classes

class IPython.core.tbtools.FrameInfo(description: str | None, filename: str, lineno: int, frame: Any, code: CodeType | None, *, sd: Any = None, context: int | None = None)

Bases: object

Mirror of stack data’s FrameInfo, but so that we can bypass highlighting on really long frames.

__init__(description: str | None, filename: str, lineno: int, frame: Any, code: CodeType | None, *, sd: Any = None, context: int | None = None)
class IPython.core.tbtools.TBTools(color_scheme: ~typing.Any = <object object>, call_pdb: bool = False, ostream: ~typing.Any = None, *, debugger_cls: type | None = None, theme_name: str = 'nocolor')

Bases: object

Basic tools used by all traceback printer classes.

__init__(color_scheme: ~typing.Any = <object object>, call_pdb: bool = False, ostream: ~typing.Any = None, *, debugger_cls: type | None = None, theme_name: str = 'nocolor')
color_toggle() None

Toggle between the currently active color scheme and nocolor.

property ostream: Any

Output stream that exceptions are written to.

Valid values are:

  • None: the default, which means that IPython will dynamically resolve to sys.stdout. This ensures compatibility with most tools, including Windows (where plain stdout doesn’t recognize ANSI escapes).

  • Any object with ‘write’ and ‘flush’ attributes.

set_colors(name: str) None

Shorthand access to the color table scheme selector method.

stb2text(stb: list[str]) str

Convert a structured traceback (a list) to a string.

structured_traceback(etype: type, evalue: BaseException | None, etb: TracebackType | None = None, tb_offset: int | None = None, context: int = 5) list[str]

Return a list of traceback frames.

Must be implemented by each class.

text(etype: type, value: BaseException | None, tb: TracebackType | None, tb_offset: int | None = None, context: int = 5) str

Return formatted traceback.

Subclasses may override this if they add extra arguments.

5 Functions

IPython.core.tbtools.count_lines_in_py_file(filename: str) int

Given a filename, returns the number of lines in the file if it ends with the extension “.py”. Otherwise, returns 0.

IPython.core.tbtools.get_line_number_of_frame(frame: FrameType) int

Given a frame object, returns the total number of lines in the file containing the frame’s code object, or the number of lines in the frame’s source code if the file is not available.

Parameters:

frame (FrameType) – The frame object whose line number is to be determined.

Returns:

The total number of lines in the file containing the frame’s code object, or the number of lines in the frame’s source code if the file is not available.

Return type:

int

IPython.core.tbtools.text_repr(value: Any) str

Hopefully pretty robust repr equivalent.

IPython.core.tbtools.eqrepr(value: ~typing.Any, repr: ~typing.Callable[[~typing.Any], str] = <function text_repr>) str
IPython.core.tbtools.nullrepr(value: ~typing.Any, repr: ~typing.Callable[[~typing.Any], str] = <function text_repr>) str