self.var
contains all the info we need
This commit is contained in:
parent
ecb9f141e4
commit
b34a5d3b54
@ -1277,8 +1277,10 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
|||||||
self._mark_dirty()
|
self._mark_dirty()
|
||||||
return
|
return
|
||||||
|
|
||||||
if not name in self.vars and not name in self._computed_var_dependencies and not name in self.get_skip_vars():
|
if name not in self.vars and name not in self.get_skip_vars():
|
||||||
raise AttributeError(f"The state var '{name}' has not been defined in '{type(self).__name__}'. All state vars must be declared before they can be set.")
|
raise AttributeError(
|
||||||
|
f"The state var '{name}' has not been defined in '{type(self).__name__}'. All state vars must be declared before they can be set."
|
||||||
|
)
|
||||||
|
|
||||||
# Set the attribute.
|
# Set the attribute.
|
||||||
super().__setattr__(name, value)
|
super().__setattr__(name, value)
|
||||||
|
@ -3265,7 +3265,8 @@ def test_child_mixin_state() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_assignment_to_undeclared_vars():
|
def test_assignment_to_undeclared_vars():
|
||||||
"""Test that an attribute error is thrown when undeclared vars are set"""
|
"""Test that an attribute error is thrown when undeclared vars are set."""
|
||||||
|
|
||||||
class State(BaseState):
|
class State(BaseState):
|
||||||
val: str
|
val: str
|
||||||
|
|
||||||
@ -3273,7 +3274,6 @@ def test_assignment_to_undeclared_vars():
|
|||||||
self.num = 5
|
self.num = 5
|
||||||
|
|
||||||
class Substate(State):
|
class Substate(State):
|
||||||
|
|
||||||
def handle_var(self):
|
def handle_var(self):
|
||||||
self.value = 20
|
self.value = 20
|
||||||
|
|
||||||
@ -3285,3 +3285,6 @@ def test_assignment_to_undeclared_vars():
|
|||||||
|
|
||||||
with pytest.raises(AttributeError):
|
with pytest.raises(AttributeError):
|
||||||
sub_state.handle()
|
sub_state.handle()
|
||||||
|
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
sub_state.handle_var()
|
||||||
|
Loading…
Reference in New Issue
Block a user