arsenal.debug package

Submodules

arsenal.debug.edit module

arsenal.debug.edit.edit(obj, verbose=True)[source]
Set the synchronize with editor hook with a callable object.
  • obj: introspection is used to retrieve relevant source code for the object; strings are treated as a filenames.
  • line : the line number to scroll to.
  • column : the column number to scroll to.
arsenal.debug.edit.emacs(filename, line=0, column=0)[source]
arsenal.debug.edit.find_filename(obj, verbose=False)[source]

Return the full filename of an instance.

arsenal.debug.util module

Debugging utilities.

arsenal.debug.util.debug(s, *args, **kwargs)[source]
>>> def foo():
...     bar = 'world'
...     debug('hello {bar}')
>>> foo()
hello world
arsenal.debug.util.debug_expr(expr)[source]

Evaluate and print the value of a string representing a python expression in the caller’s frame.

Takes an expression, evaluates it in the caller’s frame and prints both the given expression and the resulting value (as well as a debug mark indicating the name of the calling function. The input must be of a form suitable for eval().

>>> def foo():
...     x = 15
...     debug_expr('x')
...     debug_expr('x**2 + 2*x + 3')
...     f = lambda x: x**2
...     debug_expr('f(x)')
>>> foo()
[DEBUG:foo] x -> 15
[DEBUG:foo] x**2 + 2*x + 3 -> 258
[DEBUG:foo] f(x) -> 225
arsenal.debug.util.debugx(obj)[source]
I often write debugging print statements which look like
>>> somevar = 'somevalue'
>>> print('somevar:', somevar)
somevar: somevalue
What this function attempts to do is provide a shortcut
>>> debugx(somevar)
somevar: somevalue

Note: that we do not need to pass strings to this function. >>> def foo(): … x = 15 … debugx(x) … debugx(x**2 + 2*x + 3) … f = lambda x: x**2 … debugx(f(x))

>>> foo()
x: 15
x**2 + 2*x + 3: 258
f(x): 225

Warning: this should only be used for debugging because it relies on introspection, which can be really slow and sometimes even buggy.

arsenal.debug.util.dumpobj(o, callables=False, private=False)[source]
>>> class A(object):
...     x = 10
...     def __init__(self, y):
...         self.y = y
...     def span(self):
...         pass
...     def __repr__(self):
...         return 'A(%r, %r)' % (self.x, self.y)
...
>>> dumpobj(A('hello'))
A(10, 'hello')
instance of: A
                   x: int
                   y: str
>>> dumpobj(A('hello'), callables=0, private=True)
A(10, 'hello')
instance of: A
            __dict__: dict
             __doc__: NoneType
          __module__: str
         __weakref__: NoneType
                   x: int
                   y: str
arsenal.debug.util.enable_debug_hook()[source]

Register pdb’s post-mortem debugger as the handler for uncaught exceptions.

arsenal.debug.util.enable_pm()

Register pdb’s post-mortem debugger as the handler for uncaught exceptions.

arsenal.debug.util.enable_ultratb(mode='Context', **kwargs)[source]
arsenal.debug.util.framedump()[source]

Print the usual traceback information, followed by a listing of all the local variables in each frame. If this function is called when an exception has been thrown the framedump will start at the origin of the exception not where it was caught.

Module contents