-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimental): removed
expect_override
(#676) and added `trigg…
…er` and `with_trigger_decorator` expect_override (introduced recently in #676) was revoked as a heterogenous model structure is not to be expecred
- Loading branch information
Showing
2 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
def expect_override(func): | ||
setattr(func, "expect_override", True) | ||
return func | ||
from transitions.core import listify | ||
from collections import deque | ||
|
||
_attribute_name = "transition_definitions" | ||
|
||
|
||
def with_trigger_decorator(cls): | ||
add_model = getattr(cls, "add_model") | ||
|
||
def add_model_override(self, model, initial=None) -> None: | ||
self.model_override = True | ||
for model in listify(model): | ||
model = self if model == "self" else model | ||
for name, method in model.__class__.__dict__.items(): | ||
for spec in getattr(method, _attribute_name, []): | ||
self.add_transition(name, **spec) | ||
add_model(self, model, initial) | ||
|
||
setattr(cls, 'add_model', add_model_override) | ||
return cls | ||
|
||
|
||
def trigger(source, dest, conditions=None, unless=None, before=None, after=None, prepare=None): | ||
def _outer(trigger_func): | ||
if not hasattr(trigger_func, _attribute_name): | ||
setattr(trigger_func, _attribute_name, deque()) | ||
getattr(trigger_func, _attribute_name).appendleft({ | ||
"source": source, "dest": dest, "conditions": conditions, "unless": unless, "before": before, | ||
"after": after, "prepare": prepare | ||
}) | ||
return trigger_func | ||
|
||
return _outer |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
from typing import Callable, ParamSpec | ||
from typing import Union, Type, Callable | ||
from transitions.core import StateIdentifier, CallbacksArg, CallbackFunc, Machine | ||
|
||
P = ParamSpec("P") | ||
|
||
def with_trigger_decorator(cls: Type[Machine]) -> Type[Machine]: ... | ||
|
||
def expect_override(func: Callable[P, bool | None]) -> Callable[P, bool | None]: ... | ||
def trigger(source: Union[StateIdentifier, list[StateIdentifier]], | ||
dest: StateIdentifier | None = ..., | ||
conditions: CallbacksArg = ..., unless: CallbacksArg = ..., | ||
before: CallbacksArg = ..., after: CallbacksArg = ..., | ||
prepare: CallbacksArg = ...) -> Callable[[CallbackFunc], CallbackFunc]: ... |