Skip to content

Instantly share code, notes, and snippets.

@JosXa
Created October 14, 2020 22:29
Show Gist options
  • Save JosXa/5d1fbf92ee4a7f396e7468df1a560590 to your computer and use it in GitHub Desktop.
Save JosXa/5d1fbf92ee4a7f396e7468df1a560590 to your computer and use it in GitHub Desktop.
from typing import (
Iterable,
Union,
overload,
)
from uuid import uuid4
from .has_route_collection import IRouteCollection
from .state_route_builder import StateRouteBuilder
class StateMachineMixin(IRouteCollection):
@overload
def state_machine(self, states: Iterable[str]) -> Iterable[StateRouteBuilder]:
...
@overload
def state_machine(self, num_states: int) -> Iterable[StateRouteBuilder]:
...
def state_machine(self, arg: Union[int, Iterable[str]]) -> Iterable[StateRouteBuilder]:
machine_guid = uuid4()
if isinstance(arg, int):
for i in range(arg):
yield StateRouteBuilder(machine_guid, i, self._route_collection)
else:
for i, name in enumerate(arg):
yield StateRouteBuilder(machine_guid, i, self._route_collection, name=name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment