Skip to content

Commit 6d95ced

Browse files
committed
fix: handle HistoryState separately in NestedStateFactory
NestedStateFactory.__new__ was treating HistoryState as regular State (via isinstance) and adding it to states=[]. HistoryState instances need to go into history=[] for proper initialization in State.__init__.
1 parent 28c9616 commit 6d95ced

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

statemachine/state.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,23 @@ def __new__( # type: ignore [misc]
6666
inherited_kwargs.update(kwargs)
6767

6868
states = []
69+
history = []
6970
callbacks = {}
7071
for key, value in attrs.items():
71-
if isinstance(value, State):
72+
if isinstance(value, HistoryState):
73+
value._set_id(key)
74+
history.append(value)
75+
elif isinstance(value, State):
7276
value._set_id(key)
7377
states.append(value)
7478
elif isinstance(value, TransitionList):
7579
value.add_event(key)
7680
elif callable(value):
7781
callbacks[key] = value
7882

79-
return State(name=name, states=states, _callbacks=callbacks, **inherited_kwargs)
83+
return State(
84+
name=name, states=states, history=history, _callbacks=callbacks, **inherited_kwargs
85+
)
8086

8187
@classmethod
8288
def to(cls, *args: "State", **kwargs) -> "_ToState": # pragma: no cover

0 commit comments

Comments
 (0)