Created
October 14, 2020 22:29
-
-
Save JosXa/5d1fbf92ee4a7f396e7468df1a560590 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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