| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Per the card block reference, `icon` and `hero_image` are image element objects (`type`/`image_url`/`alt_text`), not plain URL strings — but CardBlock typed them as Optional[str], so passing an ImageElement (the correct, accessible form with alt_text) tripped mypy [arg-type]. Widen both to Optional[Union[str, dict, ImageElement]], matching how title/subtitle/body already accept Union[str, dict, TextObject]. Runtime serialization is unchanged (str -> bare URL, dict/ImageElement -> object); this only broadens the accepted/typed input. Docstrings updated to the reference wording. Adds a test asserting the ImageElement form round-trips. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Examples should not carry type-checker suppressions. Remove the # type: ignore[arg-type] added for the ImageElement icon/hero_image args. Until slackapi/python-slack-sdk#1937 lands (widening CardBlock.icon / hero_image to accept an image element), mypy reports [arg-type] here by design — the honest signal that slack_sdk mis-types these fields as str. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Examples should not carry type-checker suppressions. Remove the # type: ignore[arg-type] on the ImageElement icon/hero_image args. Until slackapi/python-slack-sdk#1937 lands (widening CardBlock.icon / hero_image to accept an image element), mypy reports [arg-type] here by design — the honest signal that slack_sdk mis-types these fields as str. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
|
Note on keeping str in the type The card block reference documents icon/hero_image as image-element objects only — it never shows a bare URL string. So one could argue for typing these as Union[dict, ImageElement] (object-only). This PR deliberately keeps str (Union[str, dict, ImageElement]) because:
If maintainers prefer to make these object-only, that'd be a separate major-version change (update test_document, drop str). Happy to follow up if that's the preference. |
Sorry, something went wrong.
Slack's card block schema (and the docs reference) define icon/hero_image as image element objects — a bare URL string is not a valid payload and is rejected by the API. CardBlock previously typed them as Optional[str], modeling a form that does not actually work end to end. Type both as Optional[Union[dict, ImageElement]] (object-only), matching title/subtitle/body's object-based typing. Update test_document to the documented object form (it previously passed bare-string icons). Runtime serialization of an ImageElement/dict was already correct; this drops the never-valid str form. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1937 +/- ##
=======================================
Coverage 84.17% 84.17%
=======================================
Files 118 118
Lines 13425 13425
=======================================
Hits 11301 11301
Misses 2124 2124 ☔ View full report in Codecov by Harness. |
Sorry, something went wrong.
There was a problem hiding this comment.
Leaving a callout on the breaking change that I'm marking as a patch update 📣
Sorry, something went wrong.
| hero_image: Optional[str] = None, | ||
| icon: Optional[str] = None, |
There was a problem hiding this comment.
⚠️ note: The str option is removed which typechecking might complain about but this matches what's valid with the API itself:
Sorry, something went wrong.
There was a problem hiding this comment.
Interesting 🤔 lets do a minor for this and point it out in the release notes ❤️
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for working on this 💯
Sorry, something went wrong.
| hero_image: Optional[str] = None, | ||
| icon: Optional[str] = None, |
There was a problem hiding this comment.
Interesting 🤔 lets do a minor for this and point it out in the release notes ❤️
Sorry, something went wrong.
|
@WilliamBergamin And thanks for a review and note on versioning for this change 🔏 I'll merge this now after confirming once more the error following with prior string values: invalid_blocks |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
The card block reference specifies that icon and hero_image are image element objects ({"type": "image", "image_url": ..., "alt_text": ...}), not plain URL strings. But CardBlock typed both as Optional[str], so passing an ImageElement — the correct, accessible form (it carries alt_text) — raised a mypy [arg-type] error and forced callers to use # type: ignore.
This widens both parameters to Optional[Union[str, dict, ImageElement]], matching how title/subtitle/body already accept Union[str, dict, TextObject].
Details
Testing
Motivation
Downstream: the Bolt bolt-python-examples card/carousel examples build icon/hero_image with ImageElement (docs-correct) and currently need # type: ignore[arg-type] because of this mis-typing. This fix lets those examples drop the suppression.
🤖 Generated with Claude Code