cb—callback management

takes_args(func)[source]

Determine whether the given function takes any arguments.

Returns:True if the function can take arguments, or if the result could not be determined (the argument is not a function, or not a pure-Python function), else False.
wrap_fn(func) → wrapper[source]

Return a function that calls func, possibly omitting arguments.

When wrapper is called, it calls func (and returns its return value), but only passes any arguments on to func if it is determined that func takes any arguments (using takes_args()).

class CbManager[source]

Bases: object

Simple callback manager.

cbs

Set-like container of registered callback functions.

cb(*cbs) → self[source]

Register callbacks.

If a callback is determined not to be able to take arguments, it is not passed any.

rm_cbs(*cbs) → self[source]

Remove any number of callbacks from cbs.

Missing items are ignored.

call(*args, **kwargs) → results[source]

Call all registered callbacks with the given arguments.

Returns:value returned by each callback, as {cb: result}.
class GroupedCbManager([groups])[source]

Bases: object

Manage callbacks grouped by type.

Parameters:groups – allowed groups; overrides the class’s default groups.

A group identifier may be hashable object. Groups are equivalent if they produce the same hash value.

groups = frozenset([])

Set of groups available to place callbacks in. If methods are given any other group identifier not in here, ValueError is raised.

cbs

Registered callback functions, as {group: callbacks}.

cb(group, *cbs) → self[source]

Register callbacks for a group.

If a callback is determined not to be able to take arguments, it is not passed any.

rm_cbs(group, *cbs) → self[source]

Remove any number of callbacks in a group from cbs.

Missing items are ignored.

call(group, *args, **kwargs) → results[source]

Call all registered callbacks in a group with the given arguments.

Returns:value returned by each callback, as {cb: result}.