xotl.tools.cpystack - Utilities to inspect the CPython’s stack

Utilities to inspect the CPython’s stack.


Inspects the given frame for arguments and returns a dictionary that maps parameters names to arguments values. If an * argument was passed then the key on the returning dictionary would be formatted as <name-of-*-param>[index].

For example in the function:

>>> def autocontained(a, limit, *margs, **ks):
...    import sys
...    return getargvalues(sys._getframe())

>>> autocontained(1, 12)['limit']

>>> autocontained(1, 2, -10, -11)['margs[0]']
xotl.tools.cpystack.error_info(*args, **kwargs)[source]

Get error information in current trace-back.

No all trace-back are returned, to select which are returned use:

  • args: Positional parameters

    • If string, represent the name of a function.
    • If an integer, a trace-back level.

    Return all values.

  • kwargs: The same as args but each value is a list of local names to return. If a value is True, means all local variables.

Return a list with a dict in each item.


>>> def foo(x):
...     x += 1//x
...     if x % 2:
...         bar(x - 1)
...     else:
...         bar(x - 2)

>>> def bar(x):
...     x -= 1//x
...     if x % 2:
...         foo(x//2)
...     else:
...         foo(x//3)

>>> try:    
...     foo(20)
... except:
...     print(printable_error_info('Example', foo=['x'], bar=['x']))
   ERROR: integer division or modulo by zero
xotl.tools.cpystack.object_info_finder(obj_type, arg_name=None, max_deep=25)[source]

Find an object of the given type through all arguments in stack frames.

Returns a tuple with the following values:
(arg-value, arg-name, deep, frame).

When no object is found None is returned.

object_type: a type or a tuple of types as in “isinstance”. arg_name: the arg_name to find; if None find in all arguments max_deep: the max deep to enter in the stack frames.
xotl.tools.cpystack.object_finder(obj_type, arg_name=None, max_deep=25)[source]

Find an object of the given type through all arguments in stack frames.

The difference with object_info_finder() is that this function returns the object directly, not a tuple.

xotl.tools.cpystack.track_value(value, max_deep=25)[source]

Find a value through all arguments in stack frames.

Returns a dictionary with the full-context in the same level as “value”.


Iterates through stack frames until exhausted or max_deep is reached.

To find a frame fulfilling a condition use:

frame = next(f for f in iter_stack() if condition(f))

New in version 1.6.8.


Iterates through all stack frames.

Returns tuples with the following:

(deep, filename, line_no, start_line).

New in version 1.1.3.

Deprecated since version 1.6.8: The use of params attr_filter and value_filter.