fix: replace assert with runtime guard in Slack block_kit _rich_text_list_block - #64071
fix: replace assert with runtime guard in Slack block_kit _rich_text_list_block#64071AlexFucuson9 wants to merge 1 commit into
Conversation
…uilder 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.
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
This PR replaces an assert with a runtime guard in Slack block_kit _rich_text_list_block. Small, targeted fix.
Please verify:
- The runtime guard handles the edge case that the assert was catching
- Error message is user-friendly
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (token read-only)
PR 64071: fix: replace assert with runtime guard in Slack block_kit _rich_text_list_block
Correctness ✅
- Replaces
assert cur is not None(which disappears withpython -O) with an explicit runtime guard (if cur is None: continue). - Maintains the same logical protection while being optimization-safe.
- Comment explains the intent clearly.
No issues found.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (token read-only)
PR 64071: fix: replace assert with runtime guard in Slack block_kit _rich_text_list_block
Correctness ✅
- Replaces
assert cur is not None(which disappears withpython -O) with an explicit runtime guard (if cur is None: continue). - Maintains the same logical protection while being optimization-safe.
- Comment explains the intent clearly.
No issues found.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
Changes
Slack block_kit: assert cur is not None replaced with explicit guard + continue. Prevents silent drop under python -O.
Assessment
- Defensive fix. The comment explains the rationale well.
- No debug artifacts.
Reviewed by Hermes Agent
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused defensive-cleanup proposal.
Problems
curis already guaranteed non-Noneon every loop iteration:cur_keystarts asNone(plugins/platforms/slack/block_kit.py:196), whilekeyis always a tuple (:198), so the construction at:199-207runs first. The only parser call site also appends parsed items before calling_list_block()(:442-477).- If this invariant were ever violated, the new
continuewould silently omit a Slack list item. The current optimized-mode path would instead fail atcur["elements"](:209), exposing the broken internal contract.
Suggested changes
- Keep the assertion or omit this change rather than adding a silent content-dropping recovery branch.
Automated hermes-sweeper review.
| elements.append(cur) | ||
| cur_key = key | ||
| assert cur is not None | ||
| if cur is None: |
There was a problem hiding this comment.
cur is structurally assigned before this point: key is always a tuple while cur_key begins as None. If a future refactor broke that invariant, continue would silently drop this list item; please retain the assertion or avoid adding this no-op recovery branch.
|
Merged via #69317 — your commit was cherry-picked onto current main with your authorship preserved in git history: your assert-to-runtime-guard fix was cherry-picked directly. Thanks for the contribution! |
Summary
Replace
assert cur is not Noneinplugins/platforms/slack/block_kit.py_rich_text_list_block()with an explicitif cur is None: continueguard.Why
assertstatements are stripped bypython -O, silently removing the invariant check. While this particular assert is technically unreachable (the first loop iteration always enters theif key != cur_keyblock and setscur), usingassertfor runtime invariant checking in production code is fragile.Follows the same pattern as PRs #56736, #56866, #61983, #62001, #62006, #62659, #64063.
Test Plan
python -O -c "from plugins.platforms.slack.block_kit import _rich_text_list_block"succeeds