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])
| 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. |