Skip to content

Commit bbf67f0

Browse files
nimdraugsaelclaude
andcommitted
refactor: remove redundant interrupted bool from ActiveRequest
Use `interrupt_event.is_set()` as the single source of truth instead of maintaining a separate boolean that mirrors the Event state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4b2da3e commit bbf67f0

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

src/bot/orchestrator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ class ActiveRequest:
116116
user_id: int
117117
interrupt_event: asyncio.Event = field(default_factory=asyncio.Event)
118118
progress_msg: Any = None # telegram Message object
119-
interrupted: bool = False
120119

121120

122121
class MessageOrchestrator:
@@ -1304,11 +1303,10 @@ async def _handle_stop_callback(
13041303
if not active:
13051304
await query.answer("Already completed.", show_alert=False)
13061305
return
1307-
if active.interrupted:
1306+
if active.interrupt_event.is_set():
13081307
await query.answer("Already stopping...", show_alert=False)
13091308
return
13101309

1311-
active.interrupted = True
13121310
active.interrupt_event.set()
13131311
await query.answer("Stopping...", show_alert=False)
13141312

tests/unit/test_bot/test_stop_button.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_defaults(self):
6565
req = ActiveRequest(user_id=42)
6666
assert req.user_id == 42
6767
assert isinstance(req.interrupt_event, asyncio.Event)
68-
assert req.interrupted is False
68+
assert not req.interrupt_event.is_set()
6969
assert req.progress_msg is None
7070

7171

@@ -95,7 +95,6 @@ async def test_owner_can_stop(self, orchestrator):
9595
await orchestrator._handle_stop_callback(update, context)
9696

9797
assert event.is_set()
98-
assert active.interrupted is True
9998
query.answer.assert_awaited_once_with("Stopping...", show_alert=False)
10099
progress_msg.edit_text.assert_awaited_once_with(
101100
"Stopping...", reply_markup=None
@@ -122,7 +121,6 @@ async def test_non_owner_blocked(self, orchestrator):
122121
await orchestrator._handle_stop_callback(update, context)
123122

124123
assert not event.is_set()
125-
assert not active.interrupted
126124
query.answer.assert_awaited_once_with(
127125
"Only the requesting user can stop this.", show_alert=True
128126
)
@@ -166,7 +164,7 @@ async def test_double_stop_prevention(self, orchestrator):
166164
active = ActiveRequest(
167165
user_id=100, interrupt_event=event, progress_msg=AsyncMock()
168166
)
169-
active.interrupted = True # already stopped once
167+
event.set() # already stopped once
170168
orchestrator._active_requests[100] = active
171169

172170
query = AsyncMock()

0 commit comments

Comments
 (0)