From 8fc0c086f5ab10407c294eeac5e47dff4afaf42f Mon Sep 17 00:00:00 2001 From: AlexFucuson9 Date: Tue, 14 Jul 2026 07:58:51 +0700 Subject: [PATCH] fix: replace assert with runtime guard in Slack block_kit rich_text builder assert statements are stripped when Python runs with -O flag. Replace the assert cur is not None in _rich_text_list_block() with an explicit if/continue guard. The assert is technically unreachable (first loop iteration always sets cur), but using assert for invariant checking in production code is fragile under optimization. --- plugins/platforms/slack/block_kit.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/platforms/slack/block_kit.py b/plugins/platforms/slack/block_kit.py index 881814f8265a..c67f26079943 100644 --- a/plugins/platforms/slack/block_kit.py +++ b/plugins/platforms/slack/block_kit.py @@ -227,7 +227,11 @@ def _list_block(items: List[Tuple[int, bool, str]]) -> Block: } elements.append(cur) cur_key = key - assert cur is not None + if cur is None: + # Defensive: should never happen (first iteration always enters + # the ``if key != cur_key`` block above), but guard explicitly + # so ``python -O`` doesn't silently drop the check. + continue cur["elements"].append( {"type": "rich_text_section", "elements": _nonempty_elements(_inline_elements(text))} )