fix typing issues
This commit is contained in:
parent
5c7e0f8974
commit
d773d704b4
@ -75,7 +75,6 @@ from reflex.utils.types import (
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from reflex.state import BaseState
|
from reflex.state import BaseState
|
||||||
|
|
||||||
from .function import FunctionVar
|
|
||||||
from .number import (
|
from .number import (
|
||||||
BooleanVar,
|
BooleanVar,
|
||||||
NumberVar,
|
NumberVar,
|
||||||
@ -583,36 +582,33 @@ class Var(Generic[VAR_TYPE]):
|
|||||||
# Encode the _var_data into the formatted output for tracking purposes.
|
# Encode the _var_data into the formatted output for tracking purposes.
|
||||||
return f"{constants.REFLEX_VAR_OPENING_TAG}{hashed_var}{constants.REFLEX_VAR_CLOSING_TAG}{self._js_expr}"
|
return f"{constants.REFLEX_VAR_OPENING_TAG}{hashed_var}{constants.REFLEX_VAR_CLOSING_TAG}{self._js_expr}"
|
||||||
|
|
||||||
@overload
|
|
||||||
def to(self, output: Type[StringVar]) -> StringVar: ...
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def to(self, output: Type[str]) -> StringVar: ...
|
def to(self, output: Type[str]) -> StringVar: ...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def to(self, output: Type[BooleanVar]) -> BooleanVar: ...
|
def to(self, output: Type[bool]) -> BooleanVar: ...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def to(
|
def to(self, output: type[int] | type[float] = float) -> NumberVar: ...
|
||||||
self, output: Type[NumberVar], var_type: type[int] | type[float] = float
|
|
||||||
) -> NumberVar: ...
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def to(
|
def to(
|
||||||
self,
|
self,
|
||||||
output: Type[ArrayVar],
|
output: type[list] | type[tuple] | type[set],
|
||||||
var_type: type[list] | type[tuple] | type[set] = list,
|
|
||||||
) -> ArrayVar: ...
|
) -> ArrayVar: ...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def to(
|
def to(
|
||||||
self, output: Type[ObjectVar], var_type: types.GenericType = dict
|
self, output: Type[ObjectVar], var_type: Type[VAR_INSIDE]
|
||||||
) -> ObjectVar: ...
|
) -> ObjectVar[VAR_INSIDE]: ...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def to(
|
def to(
|
||||||
self, output: Type[FunctionVar], var_type: Type[Callable] = Callable
|
self, output: Type[ObjectVar], var_type: None = None
|
||||||
) -> FunctionVar: ...
|
) -> ObjectVar[VAR_TYPE]: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def to(self, output: VAR_SUBCLASS, var_type: None = None) -> VAR_SUBCLASS: ...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def to(
|
def to(
|
||||||
@ -1189,6 +1185,9 @@ class Var(Generic[VAR_TYPE]):
|
|||||||
|
|
||||||
OUTPUT = TypeVar("OUTPUT", bound=Var)
|
OUTPUT = TypeVar("OUTPUT", bound=Var)
|
||||||
|
|
||||||
|
VAR_SUBCLASS = TypeVar("VAR_SUBCLASS", bound=Var)
|
||||||
|
VAR_INSIDE = TypeVar("VAR_INSIDE")
|
||||||
|
|
||||||
|
|
||||||
class ToOperation:
|
class ToOperation:
|
||||||
"""A var operation that converts a var to another type."""
|
"""A var operation that converts a var to another type."""
|
||||||
|
@ -239,6 +239,12 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=dict):
|
|||||||
name: str,
|
name: str,
|
||||||
) -> ObjectVar[dict[OTHER_KEY_TYPE, VALUE_TYPE]]: ...
|
) -> ObjectVar[dict[OTHER_KEY_TYPE, VALUE_TYPE]]: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def __getattr__(
|
||||||
|
self: ObjectVar,
|
||||||
|
name: str,
|
||||||
|
) -> ObjectItemOperation: ...
|
||||||
|
|
||||||
def __getattr__(self, name) -> Var:
|
def __getattr__(self, name) -> Var:
|
||||||
"""Get an attribute of the var.
|
"""Get an attribute of the var.
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import assert_type, reveal_type
|
from typing import assert_type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -96,18 +96,14 @@ def test_state_to_operation(type_: GenericType) -> None:
|
|||||||
def test_typing() -> None:
|
def test_typing() -> None:
|
||||||
# Bare
|
# Bare
|
||||||
var = ObjectState.bare.to(ObjectVar)
|
var = ObjectState.bare.to(ObjectVar)
|
||||||
reveal_type(var)
|
|
||||||
_ = assert_type(var, ObjectVar[Bare])
|
_ = assert_type(var, ObjectVar[Bare])
|
||||||
|
|
||||||
var = ObjectState.base.to(ObjectVar, Base)
|
var = ObjectState.base.to(ObjectVar, Base)
|
||||||
reveal_type(var)
|
|
||||||
_ = assert_type(var, ObjectVar[Base])
|
_ = assert_type(var, ObjectVar[Base])
|
||||||
|
|
||||||
# Base
|
# Base
|
||||||
var = ObjectState.base.to(ObjectVar)
|
var = ObjectState.base.to(ObjectVar)
|
||||||
reveal_type(var)
|
|
||||||
_ = assert_type(var, ObjectVar[Base])
|
_ = assert_type(var, ObjectVar[Base])
|
||||||
|
|
||||||
var = ObjectState.base.to(LiteralObjectVar, Base)
|
var = ObjectState.base.to(LiteralObjectVar, Base)
|
||||||
reveal_type(var)
|
_ = assert_type(var, ObjectVar[Base])
|
||||||
_ = assert_type(var, LiteralObjectVar[Base])
|
|
||||||
|
Loading…
Reference in New Issue
Block a user