Skip to content

Commit

Permalink
Add some docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Oct 21, 2023
1 parent 8d8bf6e commit 20957ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/tblib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def __init__(self, code):
class Frame:
"""
Class that replicates just enough of the builtin Frame object to enable serialization and traceback rendering.
Args:
get_locals (callable): A function that take a frame argument and returns a dict.
See :class:`Traceback` class for example.
"""

def __init__(self, frame, *, get_locals=None):
Expand All @@ -69,6 +75,21 @@ def clear(self):
class Traceback:
"""
Class that wraps builtin Traceback objects.
Args:
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:
.. code:: python
def get_locals(frame):
if frame.f_locals.get("__tracebackhide__"):
return {"__tracebackhide__": True}
else:
return {}
"""

tb_next = None
Expand Down
5 changes: 5 additions & 0 deletions src/tblib/pickling_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def _get_subclasses(cls):


def install(*exc_classes_or_instances, get_locals=None):
"""
Args:
get_locals (callable): A function that take a frame argument and returns a dict. See :class:`tblib.Traceback` class for example.
"""
copyreg.pickle(TracebackType, partial(pickle_traceback, get_locals=get_locals))

if not exc_classes_or_instances:
Expand Down

0 comments on commit 20957ca

Please sign in to comment.