File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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!" )
You can’t perform that action at this time.
0 commit comments