Util

Module

bonobo.util

The Util API, located under the bonobo.util namespace, contains helpers functions and decorators to work with and inspect transformations, graphs, and nodes.

class ValueHolder(value)[source]

Bases: object

Decorator holding a value in a given memory adress, effectively allowing to “hold” even an immutable typed value as the state of a node, allowing different actors to mutate it durably.

For the sake of concistency, all operator methods have been implemented (see https://docs.python.org/3/reference/datamodel.html) or at least all in a certain category, but it feels like a more correct method should exist, like with a getattr-something on the value. Let’s see later.

get()[source]
set(new_value)[source]
property value
class sortedlist[source]

Bases: list

insort(x)[source]
cast(type_)[source]
deprecated(func)[source]

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emmitted when the function is used.

deprecated_alias(alias, func)[source]
ensure_tuple(tuple_or_mixed, *, cls=<class 'tuple'>)[source]

If it’s not a tuple, let’s make a tuple of one item. Otherwise, not changed.

Parameters

tuple_or_mixed

Returns

tuple

get_attribute_or_create(obj, attr, default)[source]
get_name(mixed)[source]
inspect_node(mixed, *, _partial=None)[source]

If the given argument is somehow a bonobo.config.Configurable object (either a subclass, an instance, or a partially configured instance), then it will return a ConfigurableInspection namedtuple, used to inspect the configurable metadata (options). If you want to get the option values, you don’t need this, it is only usefull to perform introspection on a configurable.

If it’s not looking like a configurable, it will raise a TypeError.

Parameters

mixed

Returns

ConfigurableInspection

Raise

TypeError

isconfigurable(mixed)[source]

Check if the given argument is an instance of bonobo.config.Configurable.

Parameters

mixed

Returns

bool

isconfigurabletype(mixed, *, strict=False)[source]

Check if the given argument is an instance of bonobo.config.ConfigurableMeta, meaning it has all the plumbery necessary to build bonobo.config.Configurable-like instances.

Parameters
  • mixed

  • strict – should we consider partially configured objects?

Returns

bool

iscontextprocessor(x)[source]

Check if the given argument is an instance of bonobo.config.ContextProcessor.

Parameters

mixed

Returns

bool

isdict(mixed)[source]

Check if the given argument is a dict.

Parameters

mixed

Returns

bool

ismethod(mixed)[source]

Check if the given argument is an instance of bonobo.config.Method.

Parameters

mixed

Returns

bool

isoption(mixed)[source]

Check if the given argument is an instance of bonobo.config.Option.

Parameters

mixed

Returns

bool

istype(mixed)[source]

Check if the given argument is a type object.

Parameters

mixed

Returns

bool

tuplize(f)

Decorates a generator and make it a tuple-returning function. As a side effect, it can also decorate any iterator-returning function to force return value to be a tuple.

>>> tuplized_lambda = tuplize(lambda: [1, 2, 3])
>>> tuplized_lambda()
(1, 2, 3)
>>> @tuplize
... def my_generator():
...     yield 1
...     yield 2
...     yield 3
...
>>> my_generator()
(1, 2, 3)