Skip to content

Commit 62e99aa

Browse files
author
rodrigo.nogueira
committed
Add PR example demo for Generic[TModel] support
1 parent fd45edd commit 62e99aa

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

pr_example_demo.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Example from PR description - demonstrating Generic[TModel] support
3+
"""
4+
5+
import sys
6+
7+
sys.path.insert(0, ".")
8+
9+
from statemachine import StateMachine, State
10+
11+
12+
class MyModel:
13+
def __init__(self) -> None:
14+
self.state: str | None = None
15+
self.custom_field: str = "test"
16+
17+
18+
class MyMachine(StateMachine[MyModel]):
19+
initial = State("Initial", initial=True)
20+
processing = State("Processing")
21+
done = State("Done", final=True)
22+
23+
go = initial.to(processing)
24+
finish = processing.to(done)
25+
26+
27+
# Create instance
28+
sm = MyMachine(model=MyModel())
29+
30+
# This is what the PR description shows
31+
print(f"✅ Created state machine: {sm.current_state}")
32+
print(f"✅ Model custom_field: {sm.model.custom_field}")
33+
34+
# Demonstrate it works
35+
assert sm.model.custom_field == "test"
36+
assert sm.current_state == sm.initial
37+
38+
sm.send("go")
39+
assert sm.current_state == sm.processing
40+
41+
sm.model.custom_field = "modified"
42+
assert sm.model.custom_field == "modified"
43+
44+
sm.send("finish")
45+
assert sm.current_state == sm.done
46+
47+
48+
print(f"✅ Final state: {sm.current_state}")
49+
print(f"✅ Modified custom_field: {sm.model.custom_field}")
50+
51+
print("\n✅ PR description example works perfectly!")

0 commit comments

Comments
 (0)