@@ -153,19 +153,7 @@ def __init__(
153153 [start_value ] if start_value is not None else list (self .start_configuration_values )
154154 )
155155 self ._callbacks = CallbacksRegistry ()
156- instance_states : Dict [str , Any ] = {}
157- events = self .__class__ ._events
158- for state in self .states_map .values ():
159- ist = InstanceState (state , self )
160- instance_states [state .id ] = ist
161- if state .id not in events :
162- vars (self )[state .id ] = ist
163- self ._config = Configuration (
164- instance_states = instance_states ,
165- model = self .model ,
166- state_field = self .state_field ,
167- states_map = self .states_map ,
168- )
156+ self ._config = self ._build_configuration ()
169157 self ._listeners : Dict [int , Any ] = {}
170158 """Listeners that provides attributes to be used as callbacks."""
171159
@@ -208,6 +196,22 @@ def _resolve_class_listeners(self, **kwargs: Any) -> List[object]:
208196 resolved .append (instance )
209197 return resolved
210198
199+ def _build_configuration (self ) -> Configuration :
200+ """Create InstanceState entries and return a new Configuration."""
201+ instance_states : Dict [str , Any ] = {}
202+ events = self .__class__ ._events
203+ for state in self .states_map .values ():
204+ ist = InstanceState (state , self )
205+ instance_states [state .id ] = ist
206+ if state .id not in events :
207+ vars (self )[state .id ] = ist
208+ return Configuration (
209+ instance_states = instance_states ,
210+ model = self .model ,
211+ state_field = self .state_field ,
212+ states_map = self .states_map ,
213+ )
214+
211215 def activate_initial_state (self ) -> Any :
212216 result = self ._engine .activate_initial_state ()
213217 if not isawaitable (result ):
@@ -249,19 +253,7 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
249253 listeners = state .pop ("_listeners" )
250254 self .__dict__ .update (state ) # type: ignore[attr-defined]
251255 self ._callbacks = CallbacksRegistry ()
252- instance_states : Dict [str , Any ] = {}
253- events = self .__class__ ._events
254- for sm_state in self .states_map .values ():
255- ist = InstanceState (sm_state , self )
256- instance_states [sm_state .id ] = ist
257- if sm_state .id not in events :
258- vars (self )[sm_state .id ] = ist
259- self ._config = Configuration (
260- instance_states = instance_states ,
261- model = self .model ,
262- state_field = self .state_field ,
263- states_map = self .states_map ,
264- )
256+ self ._config = self ._build_configuration ()
265257 self ._listeners = {}
266258
267259 # _listeners already contained both class-level and runtime listeners
0 commit comments