Calls

Base Class

Call(func, *args, **kwargs)

Represent python operations.

Methods

copy()

Return a copy of this call object.

map_subcalls(f[, args, kwargs])

Call a function on all child calls.

op_vars([attr_calls])

Return set of all variable names used in Call

Subclasses

BinaryOp(func, *args, **kwargs)

Represent binary call operations.

SliceOp(func, *args, **kwargs)

Factory class for representing from single and extended slice calls.

DictCall(f, *args, **kwargs)

Calls representation of dictionary construction.

Lazy(func[, arg])

Lazily return calls rather than evaluating them.

MetaArg(func, *args, **kwargs)

Represent an argument, by returning the argument passed to __call__.

FuncArg(func, *args, **kwargs)

Represent a function to be called.

Base Class

siuba.siu.calls.Call

class siuba.siu.calls.Call(func, *args, **kwargs)

Represent python operations.

This class is responsible for representing the pieces of a python expression, as a function, along with its args and kwargs.

For example, “some_object.a” would be represented at the function “__getattr__”, with the args some_object, and “a”.

Parameters
  • func – Name of the function called. Class methods are represented using the names they have when defined on the class.

  • *args – Arguments the function call uses.

  • **kwargs – Keyword arguments the function call uses.

Examples

>>> Call("__add__", 1, 1)
(1 + 1)

See also

siuba.siu.Symbolic

Helper class for creating Calls.

Methods

siuba.siu.calls.Call.__call__

Call.__call__(x)

Evaluate a call over some context and return the result.

Note that subclasses like MetaArg, simply return the context, so that a call acts like a unary function, with x as its argument.

Parameters

x – Object passed down the call tree as context.

Examples

>>> expr = Call("__add__", MetaArg("_"), 2)
>>> expr(1)   # 1 + 2
3

siuba.siu.calls.Call.__repr__

Call.__repr__()

Return a (best guess) python code representation of the Call.

Note that this is not necessarily valid python code (e.g. if a python function is passed as a call argument).

siuba.siu.calls.Call.copy

Call.copy() siuba.siu.calls.Call

Return a copy of this call object.

Note that copies are made of child calls, but not their arguments.

siuba.siu.calls.Call.map_subcalls

Call.map_subcalls(f, args=(), kwargs=None)

Call a function on all child calls.

Parameters
  • f – A function to call on any child calls.

  • args – Optional position arguments to pass to f.

  • kwargs – Optional keyword arguments to pass to f.

Returns

  • A tuple of (new_args, new_kwargs) that can be used to recreate the original

  • Call object with transformed (copies of) child nodes.

See also

copy

Recursively calls map_subcalls to clone a call tree.

siuba.siu.calls.Call.op_vars

Call.op_vars(attr_calls=True)

Return set of all variable names used in Call

Parameters

attr_calls – whether to include called attributes (e.g. ‘a’ from _.a())

Subclasses

siuba.siu.calls.BinaryOp

class siuba.siu.calls.BinaryOp(func, *args, **kwargs)

Represent binary call operations.

siuba.siu.calls.SliceOp

class siuba.siu.calls.SliceOp(func, *args, **kwargs)

Factory class for representing from single and extended slice calls.

Note that it has SliceOpIndex, and SliceOpExt registered as subclasses, so that this class can be used rather than the specific implementations.

siuba.siu.calls.DictCall

class siuba.siu.calls.DictCall(f, *args, **kwargs)

Calls representation of dictionary construction.

Note that this class is important for two reasons:

  • Dictionary literal syntax cannot produce a call.

  • Calls cannot recognize subcalls nested inside containers. E.g. dicts, lists.

siuba.siu.calls.Lazy

class siuba.siu.calls.Lazy(func, arg=None)

Lazily return calls rather than evaluating them.

siuba.siu.calls.MetaArg

class siuba.siu.calls.MetaArg(func, *args, **kwargs)

Represent an argument, by returning the argument passed to __call__.

siuba.siu.calls.FuncArg

class siuba.siu.calls.FuncArg(func, *args, **kwargs)

Represent a function to be called.