def test_assignment_to_undeclared_vars():
    """Test that an attribute error is thrown when undeclared vars are set."""

    class State(BaseState):
        val: str
        _val: str
        __val: str  # pyright: ignore [reportGeneralTypeIssues]

        def handle_supported_regular_vars(self):
            self.val = "no underscore"
            self._val = "single leading underscore"
            self.__val = "double leading undercore"

        def handle_regular_var(self):
            self.num = 5

        def handle_backend_var(self):
            self._num = 5

        def handle_non_var(self):
            self.__num = 5

    class Substate(State):
        def handle_var(self):
            self.value = 20

    state = State()  # pyright: ignore [reportCallIssue]
    sub_state = Substate()  # pyright: ignore [reportCallIssue]

    with pytest.raises(SetUndefinedStateVarError):
        state.handle_regular_var()

    with pytest.raises(SetUndefinedStateVarError):
        sub_state.handle_var()

    with pytest.raises(SetUndefinedStateVarError):
        state.handle_backend_var()

    state.handle_supported_regular_vars()
    state.handle_non_var()
Test that an attribute error is thrown when undeclared vars are set.
tests/units/test_state.py