Skip to content

Commit 1aa8a1b

Browse files
committed
fix: simplify __setattr__ guard — remove unreachable InstanceState branch
The isinstance(value, InstanceState) check was unreachable because _build_configuration uses vars(self) directly, bypassing __setattr__. Simplify to always reject assignments to state names via __setattr__. Fixes 100% branch coverage.
1 parent 63bc62b commit 1aa8a1b

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

statemachine/statemachine.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,9 @@ def _processing_loop(self, caller_future: "Any | None" = None) -> Any:
227227
def __setattr__(self, name, value):
228228
# Fast path: internal/private attributes are never state IDs.
229229
if not name.startswith("_") and name in self.__class__.states_map:
230-
if not isinstance(value, InstanceState):
231-
raise StateMachineError(
232-
_("State overriding is not allowed. Trying to add '{}' to {}").format(
233-
value, name
234-
)
235-
)
230+
raise StateMachineError(
231+
_("State overriding is not allowed. Trying to add '{}' to {}").format(value, name)
232+
)
236233
super().__setattr__(name, value)
237234

238235
def __repr__(self):

0 commit comments

Comments
 (0)