tblib

Submodules

Package Contents

Classes

Code

Class that replicates just enough of the builtin Code object to enable serialization and traceback rendering.

Frame

Class that replicates just enough of the builtin Frame object to enable serialization and traceback rendering.

Traceback

Class that wraps builtin Traceback objects.

exception tblib.TracebackParseError[source]

Bases: Exception

Common base class for all non-exit exceptions.

class tblib.Code(code)[source]

Class that replicates just enough of the builtin Code object to enable serialization and traceback rendering.

co_code
class tblib.Frame(frame, *, get_locals=None)[source]

Class that replicates just enough of the builtin Frame object to enable serialization and traceback rendering.

Parameters:

get_locals (callable) – A function that take a frame argument and returns a dict.

See Traceback class for example.

clear()[source]

For compatibility with PyPy 3.5; clear() was added to frame in Python 3.4 and is called by traceback.clear_frames(), which in turn is called by unittest.TestCase.assertRaises

class tblib.Traceback(tb, *, get_locals=None)[source]

Class that wraps builtin Traceback objects.

Parameters:

get_locals (callable) – A function that take a frame argument and returns a dict.

Ideally you will only return exactly what you need, and only with simple types that can be json serializable.

Example:

def get_locals(frame):
    if frame.f_locals.get("__tracebackhide__"):
        return {"__tracebackhide__": True}
    else:
        return {}
tb_next
to_traceback
to_dict
as_traceback()[source]

Convert to a builtin Traceback object that is usable for raising or rendering a stacktrace.

as_dict()[source]

Converts to a dictionary representation. You can serialize the result to JSON as it only has builtin objects like dicts, lists, ints or strings.

classmethod from_dict(dct)[source]

Creates an instance from a dictionary with the same structure as .as_dict() returns.

classmethod from_string(string, strict=True)[source]

Creates an instance by parsing a stacktrace. Strict means that parsing stops when lines are not indented by at least two spaces anymore.