restrict this only to frontend vars for now.

This commit is contained in:
Elijah 2024-09-26 17:28:37 +00:00
parent dbf43b1b09
commit 15af1cade4
2 changed files with 27 additions and 3 deletions

View File

@ -1281,7 +1281,9 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
return return
if ( if (
not name.startswith("__") not name.startswith(
"_"
) # TODO: skipping backend vars and vars with double leading underscores for now. They should be supported, however.
and name not in self.vars and name not in self.vars
and name not in self.get_skip_vars() and name not in self.get_skip_vars()
): ):

View File

@ -3269,10 +3269,23 @@ def test_assignment_to_undeclared_vars():
class State(BaseState): class State(BaseState):
val: str val: str
_val: str
__val: str
def handle(self): 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 self.num = 5
def handle_backend_var(self):
self._num = 5
def handle_non_var(self):
self.__num = 5
class Substate(State): class Substate(State):
def handle_var(self): def handle_var(self):
self.value = 20 self.value = 20
@ -3281,7 +3294,16 @@ def test_assignment_to_undeclared_vars():
sub_state = Substate() # type: ignore sub_state = Substate() # type: ignore
with pytest.raises(AttributeError): with pytest.raises(AttributeError):
state.handle() state.handle_regular_var()
with pytest.raises(AttributeError): with pytest.raises(AttributeError):
sub_state.handle_var() sub_state.handle_var()
# TODO: uncomment this if the case of backend vars are supported.
# with pytest.raises(AttributeError):
# state.handle_backend_var()
#
# with pytest.raises(AttributeError):
# state.handle_non_var()
state.handle_supported_regular_vars()