Merge 13845143f8
into 68547dce4c
This commit is contained in:
commit
452df163ba
@ -26,10 +26,17 @@ def serialize_bare(obj: Bare) -> dict:
|
|||||||
return {"quantity": obj.quantity}
|
return {"quantity": obj.quantity}
|
||||||
|
|
||||||
|
|
||||||
|
class Tag(rx.Base):
|
||||||
|
"""A Tag for testing."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Base(rx.Base):
|
class Base(rx.Base):
|
||||||
"""A reflex base class with a single attribute."""
|
"""A reflex base class with a single attribute."""
|
||||||
|
|
||||||
quantity: int = 0
|
quantity: int = 0
|
||||||
|
collection: list[Tag] = []
|
||||||
|
|
||||||
|
|
||||||
class ObjectState(rx.State):
|
class ObjectState(rx.State):
|
||||||
@ -37,6 +44,16 @@ class ObjectState(rx.State):
|
|||||||
|
|
||||||
bare: rx.Field[Bare] = rx.field(Bare())
|
bare: rx.Field[Bare] = rx.field(Bare())
|
||||||
base: rx.Field[Base] = rx.field(Base())
|
base: rx.Field[Base] = rx.field(Base())
|
||||||
|
d: rx.Field[dict[str, str]] = rx.field({})
|
||||||
|
d_bool: rx.Field[dict[str, bool]] = rx.field({})
|
||||||
|
|
||||||
|
@rx.var
|
||||||
|
def computed_d(self) -> dict[str, str]:
|
||||||
|
return self.d
|
||||||
|
|
||||||
|
@rx.var
|
||||||
|
def computed_d_bool(self) -> dict[str, bool]:
|
||||||
|
return self.d_bool
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("type_", [Base, Bare])
|
@pytest.mark.parametrize("type_", [Base, Bare])
|
||||||
@ -100,3 +117,10 @@ def test_typing() -> None:
|
|||||||
# Base
|
# Base
|
||||||
var = ObjectState.base
|
var = ObjectState.base
|
||||||
_ = assert_type(var, ObjectVar[Base])
|
_ = assert_type(var, ObjectVar[Base])
|
||||||
|
|
||||||
|
# Collection
|
||||||
|
ObjectState.d["key"]
|
||||||
|
ObjectState.computed_d["key"]
|
||||||
|
ObjectState.d_bool["key"]
|
||||||
|
ObjectState.computed_d_bool["key"]
|
||||||
|
ObjectState.base.collection[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user