python-statemachine 2.3.2__tar.gz → 2.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/PKG-INFO +1 -1
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/pyproject.toml +1 -1
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/__init__.py +1 -1
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/callbacks.py +2 -3
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/engines/async_.py +2 -2
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/engines/sync.py +2 -2
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/statemachine.py +2 -5
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/states.py +19 -3
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/LICENSE +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/README.md +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/contrib/__init__.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/contrib/diagram.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/dispatcher.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/engines/__init__.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/event.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/event_data.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/events.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/exceptions.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/factory.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/graph.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/i18n.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/locale/en/LC_MESSAGES/statemachine.po +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/locale/pt_BR/LC_MESSAGES/statemachine.po +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/mixins.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/model.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/registry.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/signature.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/state.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/transition.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/transition_list.py +0 -0
- {python_statemachine-2.3.2 → python_statemachine-2.3.3}/statemachine/utils.py +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
from bisect import insort
|
|
3
|
-
from collections import Counter
|
|
4
3
|
from collections import defaultdict
|
|
5
4
|
from collections import deque
|
|
6
5
|
from enum import IntEnum
|
|
@@ -335,7 +334,7 @@ class CallbacksExecutor:
|
|
|
335
334
|
class CallbacksRegistry:
|
|
336
335
|
def __init__(self) -> None:
|
|
337
336
|
self._registry: Dict[str, CallbacksExecutor] = defaultdict(CallbacksExecutor)
|
|
338
|
-
self.
|
|
337
|
+
self.has_async_callbacks: bool = False
|
|
339
338
|
|
|
340
339
|
def clear(self):
|
|
341
340
|
self._registry.clear()
|
|
@@ -357,6 +356,6 @@ class CallbacksRegistry:
|
|
|
357
356
|
)
|
|
358
357
|
|
|
359
358
|
def async_or_sync(self):
|
|
360
|
-
self.
|
|
359
|
+
self.has_async_callbacks = any(
|
|
361
360
|
callback._iscoro for executor in self._registry.values() for callback in executor
|
|
362
361
|
)
|
|
@@ -31,9 +31,9 @@ class AsyncEngine:
|
|
|
31
31
|
Given how async works on python, there's no built-in way to activate the initial state that
|
|
32
32
|
may depend on async code from the StateMachine.__init__ method.
|
|
33
33
|
"""
|
|
34
|
-
return await self.
|
|
34
|
+
return await self.processing_loop()
|
|
35
35
|
|
|
36
|
-
async def
|
|
36
|
+
async def processing_loop(self):
|
|
37
37
|
"""Process event triggers.
|
|
38
38
|
|
|
39
39
|
The simplest implementation is the non-RTC (synchronous),
|
|
@@ -29,9 +29,9 @@ class SyncEngine:
|
|
|
29
29
|
Given how async works on python, there's no built-in way to activate the initial state that
|
|
30
30
|
may depend on async code from the StateMachine.__init__ method.
|
|
31
31
|
"""
|
|
32
|
-
return self.
|
|
32
|
+
return self.processing_loop()
|
|
33
33
|
|
|
34
|
-
def
|
|
34
|
+
def processing_loop(self):
|
|
35
35
|
"""Process event triggers.
|
|
36
36
|
|
|
37
37
|
The simplest implementation is the non-RTC (synchronous),
|
|
@@ -106,7 +106,7 @@ class StateMachine(metaclass=StateMachineMetaclass):
|
|
|
106
106
|
self._engine = self._get_engine(rtc)
|
|
107
107
|
|
|
108
108
|
def _get_engine(self, rtc: bool):
|
|
109
|
-
if self._callbacks_registry.
|
|
109
|
+
if self._callbacks_registry.has_async_callbacks:
|
|
110
110
|
return AsyncEngine(self, rtc=rtc)
|
|
111
111
|
else:
|
|
112
112
|
return SyncEngine(self, rtc=rtc)
|
|
@@ -118,7 +118,7 @@ class StateMachine(metaclass=StateMachineMetaclass):
|
|
|
118
118
|
return run_async_from_sync(result)
|
|
119
119
|
|
|
120
120
|
def _processing_loop(self):
|
|
121
|
-
return self._engine.
|
|
121
|
+
return self._engine.processing_loop()
|
|
122
122
|
|
|
123
123
|
def __init_subclass__(cls, strict_states: bool = False):
|
|
124
124
|
cls._strict_states = strict_states
|
|
@@ -303,9 +303,6 @@ class StateMachine(metaclass=StateMachineMetaclass):
|
|
|
303
303
|
def send(self, event: str, *args, **kwargs):
|
|
304
304
|
"""Send an :ref:`Event` to the state machine.
|
|
305
305
|
|
|
306
|
-
This is a thin wrapper around :meth:`async_send` to allow synchronous
|
|
307
|
-
code to send events.
|
|
308
|
-
|
|
309
306
|
.. seealso::
|
|
310
307
|
|
|
311
308
|
See: :ref:`triggering events`.
|
|
@@ -54,7 +54,6 @@ class States:
|
|
|
54
54
|
return list(self) == list(other)
|
|
55
55
|
|
|
56
56
|
def __getattr__(self, name: str):
|
|
57
|
-
name = name.lower()
|
|
58
57
|
if name in self._states:
|
|
59
58
|
return self._states[name]
|
|
60
59
|
raise AttributeError(f"{name} not found in {self.__class__.__name__}")
|
|
@@ -81,7 +80,7 @@ class States:
|
|
|
81
80
|
return self._states.items()
|
|
82
81
|
|
|
83
82
|
@classmethod
|
|
84
|
-
def from_enum(cls, enum_type: EnumType, initial, final=None):
|
|
83
|
+
def from_enum(cls, enum_type: EnumType, initial, final=None, use_enum_instance: bool = False):
|
|
85
84
|
"""
|
|
86
85
|
Creates a new instance of the ``States`` class from an enumeration.
|
|
87
86
|
|
|
@@ -125,12 +124,25 @@ class States:
|
|
|
125
124
|
True
|
|
126
125
|
|
|
127
126
|
>>> sm.current_state_value
|
|
127
|
+
2
|
|
128
|
+
|
|
129
|
+
If you need to use the enum instance as the state value, you can set the
|
|
130
|
+
``use_enum_instance=True``:
|
|
131
|
+
|
|
132
|
+
>>> states = States.from_enum(Status, initial=Status.pending, use_enum_instance=True)
|
|
133
|
+
>>> states.completed.value
|
|
128
134
|
<Status.completed: 2>
|
|
129
135
|
|
|
136
|
+
.. deprecated:: 2.3.3
|
|
137
|
+
|
|
138
|
+
On the next major release, the ``use_enum_instance=True`` will be the default.
|
|
139
|
+
|
|
130
140
|
Args:
|
|
131
141
|
enum_type: An enumeration containing the states of the machine.
|
|
132
142
|
initial: The initial state of the machine.
|
|
133
143
|
final: A set of final states of the machine.
|
|
144
|
+
use_enum_instance: If ``True``, the value of the state will be the enum item instance,
|
|
145
|
+
otherwise the enum item value.
|
|
134
146
|
|
|
135
147
|
Returns:
|
|
136
148
|
A new instance of the :ref:`States (class)`.
|
|
@@ -138,7 +150,11 @@ class States:
|
|
|
138
150
|
final_set = set(ensure_iterable(final))
|
|
139
151
|
return cls(
|
|
140
152
|
{
|
|
141
|
-
e.name
|
|
153
|
+
e.name: State(
|
|
154
|
+
value=(e if use_enum_instance else e.value),
|
|
155
|
+
initial=e is initial,
|
|
156
|
+
final=e in final_set,
|
|
157
|
+
)
|
|
142
158
|
for e in enum_type
|
|
143
159
|
}
|
|
144
160
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|