Skip to content

Commit 694ec2f

Browse files
k1e1n04seratch
andauthored
Fix #1468 RichTextElement.elements items are never promoted to a proper Python object type (#1492)
Co-authored-by: Kazuhiro Sera <[email protected]>
1 parent 059dd68 commit 694ec2f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

slack_sdk/models/blocks/block_elements.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ def __init__(
18681868
):
18691869
super().__init__(type=self.type)
18701870
show_unknown_key_warning(self, others)
1871-
self.elements = elements
1871+
self.elements = BlockElement.parse_all(elements)
18721872
self.style = style
18731873
self.indent = indent
18741874
self.offset = offset
@@ -1891,7 +1891,7 @@ def __init__(
18911891
):
18921892
super().__init__(type=self.type)
18931893
show_unknown_key_warning(self, others)
1894-
self.elements = elements
1894+
self.elements = BlockElement.parse_all(elements)
18951895
self.border = border
18961896

18971897

@@ -1910,7 +1910,7 @@ def __init__(
19101910
):
19111911
super().__init__(type=self.type)
19121912
show_unknown_key_warning(self, others)
1913-
self.elements = elements
1913+
self.elements = BlockElement.parse_all(elements)
19141914

19151915

19161916
class RichTextSectionElement(RichTextElement):
@@ -1928,7 +1928,7 @@ def __init__(
19281928
):
19291929
super().__init__(type=self.type)
19301930
show_unknown_key_warning(self, others)
1931-
self.elements = elements
1931+
self.elements = BlockElement.parse_all(elements)
19321932

19331933

19341934
class RichTextElementParts:

tests/slack_sdk/models/test_blocks.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,3 +1083,38 @@ def test_complex(self):
10831083
],
10841084
)
10851085
self.assertDictEqual(dict_block, class_block.to_dict())
1086+
1087+
def test_elements_are_parsed(self):
1088+
dict_block = {
1089+
"type": "rich_text",
1090+
"elements": [
1091+
{
1092+
"type": "rich_text_section",
1093+
"elements": [{"type": "text", "text": "Hello there, I am a basic rich text block!"}],
1094+
},
1095+
{
1096+
"type": "rich_text_quote",
1097+
"elements": [{"type": "text", "text": "this is very important"}],
1098+
},
1099+
{
1100+
"type": "rich_text_preformatted",
1101+
"elements": [{"type": "text", "text": 'print("Hello world")'}],
1102+
},
1103+
{
1104+
"type": "rich_text_list",
1105+
"elements": [
1106+
{"type": "rich_text_section", "elements": [{"type": "text", "text": "a"}]},
1107+
],
1108+
},
1109+
],
1110+
}
1111+
block = RichTextBlock(**dict_block)
1112+
self.assertIsInstance(block.elements[0], RichTextSectionElement)
1113+
self.assertIsInstance(block.elements[0].elements[0], RichTextElementParts.Text)
1114+
self.assertIsInstance(block.elements[1], RichTextQuoteElement)
1115+
self.assertIsInstance(block.elements[1].elements[0], RichTextElementParts.Text)
1116+
self.assertIsInstance(block.elements[2], RichTextPreformattedElement)
1117+
self.assertIsInstance(block.elements[2].elements[0], RichTextElementParts.Text)
1118+
self.assertIsInstance(block.elements[3], RichTextListElement)
1119+
self.assertIsInstance(block.elements[3].elements[0], RichTextSectionElement)
1120+
self.assertIsInstance(block.elements[3].elements[0].elements[0], RichTextElementParts.Text)

0 commit comments

Comments
 (0)