python-statemachine
python-statemachine copied to clipboard
Feature request logic_OR logic_NOT wrappers for conditions (and unless condition)
That is best python state machine libratry! Thanks!
Description
Im my case i build logic with many states (> 12), also a have many conditions. My way is simple conditions and build transitions logic with combinations of simple transitions. I hepls me keep code clear.
I catch a problem with clearing code. If transition conditions all true or all negative - its ok. But if condition is any of i can't easy add it to class_declaration. For solve this i need make class method which wil wraps my base conditions with logic or.
async def is_aggregater_logic_or_condition(self, event_data):
return self.condition1(event_data) or (await self.simple_condition_2(event_data))
What I want
I would really like to use some wrappers. Need or_condition_wrapper and not_cond_wrapper to wraps many conditions. This will allow you to configure the state machine more flexibly and write cleaner code.
For example:
...
|_.initialized.to(_.waiting_create_by_order_conditions, # init to wait_create_by_order_conditions
cond=[ ],
unless=[
State_machine.or_wrapper( 'is_any_trade_buy_presented',
'is_can_create_order_buy',
'is_buy_price_close_to_market_price',
'is_free_deposit_far_to_limit',
'is_enough_free_money',) _# means that we went to_waiting_create_by_order_conditions if any one of conditions is negative
],
validators=[ 'val_separator','val_update_dep_data']
) \
Thanks is advance