Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class NoNextStates(NamedTuple):
"""Represents the lack of a next state to progress to."""
def next_state_for_label(self, label_context: Any) -> str:
"""Invalid to call, raise an exception."""
raise RuntimeError(
"Attempted to progress from a state with no next state",
)
def all_destinations(self) -> Iterable[str]:
"""Returns no states."""
return []
NextStates = Union[ConstantNextState, ContextNextStates, NoNextStates]
class Gate(NamedTuple):
"""
A state that restricts a label from moving based on an exit condition.
Gates cannot perform an action.
"""
name: str
next_states: NextStates
exit_condition: ExitConditionProgram
triggers: Iterable[Trigger]
@property
def metadata_triggers(self) -> List[MetadataTrigger]:
def _load_next_states(
path: Path,
yaml_next_states: Optional[Yaml],
feed_names: List[str],
) -> NextStates:
if yaml_next_states is None:
return NoNextStates()
if isinstance(yaml_next_states, str):
return _load_constant_next_state(path, {'state': yaml_next_states})
if yaml_next_states['type'] == 'constant':
return _load_constant_next_state(path, yaml_next_states)
elif yaml_next_states['type'] == 'context': # pragma: no branch
return _load_context_next_states(path, yaml_next_states, feed_names)
else:
raise ConfigError( # pragma: no cover
f"Next state config at path {'.'.join(path)} must be of type "
f"'constant' or 'context'",
) from None