Skip to content

Commit

Permalink
Fix #1468 RichTextElement.elements items are never promoted to a pr…
Browse files Browse the repository at this point in the history
…oper Python object type (#1492)

Co-authored-by: Kazuhiro Sera <seratch@gmail.com>
  • Loading branch information
k1e1n04 and seratch committed May 3, 2024
1 parent 059dd68 commit 694ec2f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions slack_sdk/models/blocks/block_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ def __init__(
):
super().__init__(type=self.type)
show_unknown_key_warning(self, others)
self.elements = elements
self.elements = BlockElement.parse_all(elements)
self.style = style
self.indent = indent
self.offset = offset
Expand All @@ -1891,7 +1891,7 @@ def __init__(
):
super().__init__(type=self.type)
show_unknown_key_warning(self, others)
self.elements = elements
self.elements = BlockElement.parse_all(elements)
self.border = border


Expand All @@ -1910,7 +1910,7 @@ def __init__(
):
super().__init__(type=self.type)
show_unknown_key_warning(self, others)
self.elements = elements
self.elements = BlockElement.parse_all(elements)


class RichTextSectionElement(RichTextElement):
Expand All @@ -1928,7 +1928,7 @@ def __init__(
):
super().__init__(type=self.type)
show_unknown_key_warning(self, others)
self.elements = elements
self.elements = BlockElement.parse_all(elements)


class RichTextElementParts:
Expand Down
35 changes: 35 additions & 0 deletions tests/slack_sdk/models/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,38 @@ def test_complex(self):
],
)
self.assertDictEqual(dict_block, class_block.to_dict())

def test_elements_are_parsed(self):
dict_block = {
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": "Hello there, I am a basic rich text block!"}],
},
{
"type": "rich_text_quote",
"elements": [{"type": "text", "text": "this is very important"}],
},
{
"type": "rich_text_preformatted",
"elements": [{"type": "text", "text": 'print("Hello world")'}],
},
{
"type": "rich_text_list",
"elements": [
{"type": "rich_text_section", "elements": [{"type": "text", "text": "a"}]},
],
},
],
}
block = RichTextBlock(**dict_block)
self.assertIsInstance(block.elements[0], RichTextSectionElement)
self.assertIsInstance(block.elements[0].elements[0], RichTextElementParts.Text)
self.assertIsInstance(block.elements[1], RichTextQuoteElement)
self.assertIsInstance(block.elements[1].elements[0], RichTextElementParts.Text)
self.assertIsInstance(block.elements[2], RichTextPreformattedElement)
self.assertIsInstance(block.elements[2].elements[0], RichTextElementParts.Text)
self.assertIsInstance(block.elements[3], RichTextListElement)
self.assertIsInstance(block.elements[3].elements[0], RichTextSectionElement)
self.assertIsInstance(block.elements[3].elements[0].elements[0], RichTextElementParts.Text)

0 comments on commit 694ec2f

Please sign in to comment.