From 6378ed21ca62c9d772095c1b792ba41d8d6be4d7 Mon Sep 17 00:00:00 2001 From: break27 Date: Tue, 28 Apr 2026 17:35:32 +0800 Subject: [PATCH] fix: added exceptions --- src/common/actionflow.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/actionflow.py b/src/common/actionflow.py index 024d2b4..4201167 100644 --- a/src/common/actionflow.py +++ b/src/common/actionflow.py @@ -1,4 +1,6 @@ from abc import abstractmethod, ABCMeta +class Unavailable(BaseException): pass +class NotAllowed(BaseException): pass class Action(BaseException, metaclass=ABCMeta): def __init__(self, *args): @@ -26,10 +28,11 @@ class ActionFlow: def do(self, action: str): index = self.indices.get(action) assert index is not None - - if self.on[index] is not None: - value = self.actions[index].prepare() - self.on[index] = value + + if self.on[index]: raise Unavailable(action) + if self.on[index] is None: raise NotAllowed(action) + value = self.actions[index].prepare() + self.on[index] = bool(value) def react(self): for index in self.indices.values(): @@ -43,7 +46,7 @@ class ActionFlow: assert index is not None return index - def allow(self, kind, value: bool): + def allow(self, kind, value=True): index = self.index(kind) self.on[index] = False if value else None @@ -65,4 +68,4 @@ class ActionFlow: def capabilities(self) -> dict[str, bool]: items = self.indices.items() - return { k: self.on[v] == False for k, v in items } + return { k: not self.on[v] for k, v in items if self.on[v] is not None }