Skip to content

utilities

Utility methods.

FUNCTION DESCRIPTION
diff_index

Return the index where iterable2 is different from iterable1.

eval_if_callable

Tries to evaluate value as an action, a pipeline, or a callable if possible.

is_action

Returns True if the value is an action.

is_pipeline

Returns True if the value is a pipeline.

pairs

Return successive pairs taken from the input iterable.

resolve_name

Get a key or attr name from obj or default value.

Functions

diff_index

diff_index(iterable1: Iterable, iterable2: Iterable) -> Optional[int]

Return the index where iterable2 is different from iterable1.

eval_if_callable

eval_if_callable(value: Any) -> Any

Tries to evaluate value as an action, a pipeline, or a callable if possible.

PARAMETER DESCRIPTION
value

A callable, action dictionary, list of action dictionaries, or other.

TYPE: Any

RETURNS DESCRIPTION
Any

The original value if it cannot be evaluated further.

is_action

is_action(value: Any) -> bool

Returns True if the value is an action.

is_pipeline

is_pipeline(value: Any) -> bool

Returns True if the value is a pipeline.

pairs

pairs(iterable: Iterable) -> Iterable

Return successive pairs taken from the input iterable.

Like itertools.pairwise in 3.10, but will always include the last element by itself.

Example

list(pairs(“ABCD”)) [(“A”, “B”), (“B”, “C”), (“C”, “D”), (“D”, None)] list(pairs(“ABC”)) [(“A”, “B”), (“B”, “C”), (“C”, None)]

PARAMETER DESCRIPTION
iterable

The iterable to combine into pairs.

TYPE: Iterable

RETURNS DESCRIPTION
Iterable

An iterable of pairs.

resolve_name

resolve_name(obj: Any, name: str, default: Any = None) -> Any

Get a key or attr name from obj or default value.

Copied and modified from Django Template variable resolutions

Resolution methods:

  • Mapping key lookup
  • Attribute lookup
  • Sequence index
PARAMETER DESCRIPTION
obj

The object to access

TYPE: Any

name

A dotted name to the value, such as mykey.0.name

TYPE: str

default

If the name cannot be resolved from the object, return this value

TYPE: Any DEFAULT: None

RETURNS DESCRIPTION
Any

The value at the resolved name or the default value.

RAISES DESCRIPTION
TypeError

If accessing the property raises one of these exceptions.

AttributeError

If accessing the property raises one of these exceptions.