MCPcopy
hub / github.com/reflex-dev/reflex / get_state

Method get_state

reflex/istate/proxy.py:295–317  ·  view source on GitHub ↗

Get an instance of the state associated with this token. Args: state_cls: The class of the state. Returns: The state. Raises: ImmutableStateError: If the state is not in mutable mode.

(self, state_cls: type[T_STATE])

Source from the content-addressed store, hash-verified

293 return self.__wrapped__.get_substate(path)
294
295 async def get_state(self, state_cls: type[T_STATE]) -> T_STATE:
296 """Get an instance of the state associated with this token.
297
298 Args:
299 state_cls: The class of the state.
300
301 Returns:
302 The state.
303
304 Raises:
305 ImmutableStateError: If the state is not in mutable mode.
306 """
307 if not self._is_mutable():
308 msg = (
309 "Background task StateProxy is immutable outside of a context "
310 "manager. Use `async with self` to modify state."
311 )
312 raise ImmutableStateError(msg)
313 return type(self)(
314 await self.__wrapped__.get_state(state_cls),
315 event=self._self_event,
316 parent_state_proxy=self,
317 ) # pyright: ignore [reportReturnType]
318
319 async def _as_state_update(self, *args, **kwargs) -> StateUpdate:
320 """Temporarily allow mutability to access parent_state.

Callers 6

test_state_proxyFunction · 0.95
_unlinkMethod · 0.45
_modify_linked_statesMethod · 0.45
__aenter__Method · 0.45
get_stateFunction · 0.45

Calls 2

_is_mutableMethod · 0.95
ImmutableStateErrorClass · 0.90

Tested by 1

test_state_proxyFunction · 0.76