Skip to content

Commit d22034a

Browse files
authored
add generic field to get_state in proxy (#5415)
1 parent f6998de commit d22034a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

reflex/istate/proxy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import json
1111
from collections.abc import Callable, Sequence
1212
from types import MethodType
13-
from typing import TYPE_CHECKING, Any, SupportsIndex
13+
from typing import TYPE_CHECKING, Any, SupportsIndex, TypeVar
1414

1515
import pydantic
1616
import wrapt
@@ -27,6 +27,8 @@
2727
if TYPE_CHECKING:
2828
from reflex.state import BaseState, StateUpdate
2929

30+
T_STATE = TypeVar("T_STATE", bound="BaseState")
31+
3032

3133
class StateProxy(wrapt.ObjectProxy):
3234
"""Proxy of a state instance to control mutability of vars for a background task.
@@ -269,7 +271,7 @@ def get_substate(self, path: Sequence[str]) -> BaseState:
269271
raise ImmutableStateError(msg)
270272
return self.__wrapped__.get_substate(path)
271273

272-
async def get_state(self, state_cls: type[BaseState]) -> BaseState:
274+
async def get_state(self, state_cls: type[T_STATE]) -> T_STATE:
273275
"""Get an instance of the state associated with this token.
274276

275277
Args:
@@ -289,7 +291,7 @@ async def get_state(self, state_cls: type[BaseState]) -> BaseState:
289291
raise ImmutableStateError(msg)
290292
return type(self)(
291293
await self.__wrapped__.get_state(state_cls), parent_state_proxy=self
292-
)
294+
) # pyright: ignore [reportReturnType]
293295

294296
async def _as_state_update(self, *args, **kwargs) -> StateUpdate:
295297
"""Temporarily allow mutability to access parent_state.

0 commit comments

Comments
 (0)