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.
This commit is contained in:
AlexFucuson9 2026-07-14 07:58:51 +07:00 committed by Teknium
parent d91a143977
commit 8fc0c086f5

View file

@ -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))}
)