This commit is contained in:
benedikt-bartscher 2025-02-01 20:42:10 +01:00 committed by GitHub
commit 452df163ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,10 +26,17 @@ def serialize_bare(obj: Bare) -> dict:
return {"quantity": obj.quantity}
class Tag(rx.Base):
"""A Tag for testing."""
pass
class Base(rx.Base):
"""A reflex base class with a single attribute."""
quantity: int = 0
collection: list[Tag] = []
class ObjectState(rx.State):
@ -37,6 +44,16 @@ class ObjectState(rx.State):
bare: rx.Field[Bare] = rx.field(Bare())
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])
@ -100,3 +117,10 @@ def test_typing() -> None:
# Base
var = ObjectState.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]