Transition#

This module defines a transition class that is used to specify conditions and destinations for transitions to nodes.

class Transition(*, cnd=True, dst, priority=None)[source]#

Bases: BaseModel

A basic class for a transition to a node.

cnd: AnyCondition#

A condition that determines if transition is allowed to happen.

dst: AnyDestination#

Destination node of the transition.

priority: AnyPriority#

Priority of the transition. Higher priority transitions are resolved first.

async get_next_label(ctx, transitions, default_priority)[source]#

Determine the next node based on transitions and ctx.

The process is as follows:

  1. Condition result is calculated for every transition.

  2. Transitions are filtered by the calculated condition.

  3. Priority result is calculated for every transition that is left. default_priority is used for priorities that return True or None as per BasePriority. Those that return False are filtered out.

  4. Destination result is calculated for every transition that is left.

  5. The highest priority transition is chosen. If there are multiple transition of the higher priority, choose the first one of that priority in the transitions list. Order of transitions is as follows: node transitions, local transitions, global transitions.

If at any point any BaseCondition, BaseDestination or BasePriority produces an exception, the corresponding transition is filtered out.

Return type:

Optional[AbsoluteNodeLabel]

Returns:

Label of the next node or None if no transition is left by the end of the process.