def test_computed_var_dependencies():
    """Test that a ComputedVar correctly tracks its dependencies."""

    class ComputedState(BaseState):
        v: int = 0
        w: int = 0
        x: int = 0
        y: list[int] = [1, 2, 3]
        _z: list[int] = [1, 2, 3]

        @property
        def testprop(self) -> int:
            return self.v

        @rx.var
        def comp_v(self) -> int:
            """Direct access.

            Returns:
                The value of self.v.
            """
            return self.v

        @rx.var(backend=True)
        def comp_v_backend(self) -> int:
            """Direct access backend var.

            Returns:
                The value of self.v.
            """
            return self.v

        @rx.var
        def comp_v_via_property(self) -> int:
            """Access v via property.

            Returns:
                The value of v via property.
            """
            return self.testprop

        @rx.var
        def comp_w(self) -> Callable[[], int]:
            """Nested lambda.

            Returns:
                A lambda that returns the value of self.w.
            """
            return lambda: self.w

        @rx.var
        def comp_x(self) -> Callable[[], int]:
            """Nested function.

            Returns:
                A function that returns the value of self.x.
            """

            def _():
                return self.x

            return _

        @rx.var
        def comp_y(self) -> list[int]:
            """Comprehension iterating over attribute.

            Returns:
                A list of the values of self.y.
            """
            return [round(y) for y in self.y]

        @rx.var
        def comp_z(self) -> list[bool]:
            """Comprehension accesses attribute.

            Returns:
                A list of whether the values 0-4 are in self._z.
            """
            return [z in self._z for z in range(5)]

    cs = ComputedState()
    assert cs._var_dependencies["v"] == {
        (ComputedState.get_full_name(), "comp_v"),
        (ComputedState.get_full_name(), "comp_v_backend"),
        (ComputedState.get_full_name(), "comp_v_via_property"),
    }
    assert cs._var_dependencies["w"] == {(ComputedState.get_full_name(), "comp_w")}
    assert cs._var_dependencies["x"] == {(ComputedState.get_full_name(), "comp_x")}
    assert cs._var_dependencies["y"] == {(ComputedState.get_full_name(), "comp_y")}
    assert cs._var_dependencies["_z"] == {(ComputedState.get_full_name(), "comp_z")}
Test that a ComputedVar correctly tracks its dependencies.
tests/units/test_state.py