feat(models): add typed model classes for TableBlock cells and column_settings - #1939
Open
srtaalej wants to merge 6 commits into
Open
feat(models): add typed model classes for TableBlock cells and column_settings#1939srtaalej wants to merge 6 commits into
srtaalej wants to merge 6 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1939 +/- ##
==========================================
- Coverage 84.17% 84.11% -0.07%
==========================================
Files 118 118
Lines 13425 13442 +17
==========================================
+ Hits 11301 11307 +6
- Misses 2124 2135 +11 ☔ View full report in Codecov by Harness. |
srtaalej
marked this pull request as ready for review
August 6, 2026 19:11
zimeg
reviewed
Aug 7, 2026
Comment on lines
+232
to
+271
| class RichTextCell(JsonObject): | ||
| """A rich_text typed cell for use in TableBlock rows.""" | ||
|
|
||
| type = "rich_text" | ||
|
|
||
| @property | ||
| def attributes(self) -> Set[str]: | ||
| return {"type", "elements"} | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| elements: Sequence[Union[Dict[str, Any], Any]], | ||
| **others: dict, | ||
| ): | ||
| """A rich text cell used in table block rows. | ||
| https://docs.slack.dev/reference/block-kit/blocks/table-block | ||
|
|
||
| Args: | ||
| elements (required): An array of rich text element objects | ||
| (rich_text_section, rich_text_list, rich_text_quote, rich_text_preformatted). | ||
| """ | ||
| show_unknown_key_warning(self, others) | ||
| self.type = self.__class__.type | ||
| from slack_sdk.models.blocks.block_elements import BlockElement | ||
|
|
||
| self.elements = BlockElement.parse_all(elements) | ||
|
|
||
| @classmethod | ||
| def parse(cls, cell: Optional[Union[Dict[str, Any], "RichTextCell"]]) -> Optional["RichTextCell"]: | ||
| if cell is None: | ||
| return None | ||
| if isinstance(cell, RichTextCell): | ||
| return cell | ||
| if isinstance(cell, dict): | ||
| d = {k: v for k, v in cell.items() if k != "type"} | ||
| return RichTextCell(**d) | ||
| return None | ||
|
|
||
|
|
Member
There was a problem hiding this comment.
Suggested change
| class RichTextCell(JsonObject): | |
| """A rich_text typed cell for use in TableBlock rows.""" | |
| type = "rich_text" | |
| @property | |
| def attributes(self) -> Set[str]: | |
| return {"type", "elements"} | |
| def __init__( | |
| self, | |
| *, | |
| elements: Sequence[Union[Dict[str, Any], Any]], | |
| **others: dict, | |
| ): | |
| """A rich text cell used in table block rows. | |
| https://docs.slack.dev/reference/block-kit/blocks/table-block | |
| Args: | |
| elements (required): An array of rich text element objects | |
| (rich_text_section, rich_text_list, rich_text_quote, rich_text_preformatted). | |
| """ | |
| show_unknown_key_warning(self, others) | |
| self.type = self.__class__.type | |
| from slack_sdk.models.blocks.block_elements import BlockElement | |
| self.elements = BlockElement.parse_all(elements) | |
| @classmethod | |
| def parse(cls, cell: Optional[Union[Dict[str, Any], "RichTextCell"]]) -> Optional["RichTextCell"]: | |
| if cell is None: | |
| return None | |
| if isinstance(cell, RichTextCell): | |
| return cell | |
| if isinstance(cell, dict): | |
| d = {k: v for k, v in cell.items() if k != "type"} | |
| return RichTextCell(**d) | |
| return None |
🪓 note: I think here we can use the existing RichTextBlock similar to @slack/types implementation:
| return len(self.text) >= 1 | ||
|
|
||
|
|
||
| class ColumnSettings(JsonObject): |
Member
There was a problem hiding this comment.
Suggested change
| class ColumnSettings(JsonObject): | |
| class TableBlockColumnSettings(JsonObject): |
📣 note: Hoping to namespace this to match the @slack/types package too but also to avoid confusion on which columns this settings are applied:
👾 note: Please know I'm less confident about this change so consider it a non-blocking preference!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds typed model classes for
TableBlockcells and column settings, so developers get autocomplete and validation instead of hand-building dicts.TableBlockColumnSettings— typed class for column settings withalignandis_wrappedRichTextBlock(pre-existing) — already coversrich_texttable cellsRawTextObject(pre-existing) — already coversraw_textcellsTableBlocktype annotations are widened to accept both typed objects and raw dicts for full backward compatibility.Closes #1938
Testing
Test app.py
Requirements