diff --git a/blockkit/components.py b/blockkit/components.py index 5ab35f6..9f8a52b 100644 --- a/blockkit/components.py +++ b/blockkit/components.py @@ -1,6 +1,5 @@ import json from typing import Any, List, Type -from typing import get_type_hints from pydantic import BaseModel, model_validator @@ -19,9 +18,8 @@ def get_args(tp): class Component(BaseModel): @model_validator(mode="after") def expand_strings(self) -> Any: - hints = get_type_hints(self) - for field_name, types in hints.items(): - inner_types = self._get_inner_types(types) + for field_name, field in self.model_fields.items(): + inner_types = self._get_inner_types(field.annotation) if not inner_types: continue diff --git a/blockkit/elements.py b/blockkit/elements.py index 69831c8..7640fa3 100644 --- a/blockkit/elements.py +++ b/blockkit/elements.py @@ -51,7 +51,7 @@ "RichTextQuote", "RichTextSection", "RichTextList", - "FileInput" + "FileInput", ] @@ -719,6 +719,7 @@ def __init__( ): super().__init__(elements=elements, style=style, indent=indent) + class FileInput(ActionableComponent): type: str = "file_input" filetypes: Optional[List[str]] = Field(None) @@ -735,4 +736,5 @@ def __init__( action_id=action_id, filetypes=filetypes, max_files=max_files, - ) \ No newline at end of file + ) + diff --git a/blockkit/objects.py b/blockkit/objects.py index 1462087..aa62a64 100644 --- a/blockkit/objects.py +++ b/blockkit/objects.py @@ -29,6 +29,11 @@ class MarkdownText(Component): def __init__(self, *, text: str, verbatim: Optional[bool] = None): super().__init__(text=text, verbatim=verbatim) + def __eq__(self, other): + if not isinstance(other, type(self)): + return False + return self.text == other.text + class PlainText(Component): type: str = "plain_text" @@ -38,6 +43,11 @@ class PlainText(Component): def __init__(self, *, text: str, emoji: Optional[bool] = None): super().__init__(text=text, emoji=emoji) + def __eq__(self, other): + if not isinstance(other, type(self)): + return False + return self.text == other.text + class Style(Component): bold: Optional[bool] = None diff --git a/tests/test_elements.py b/tests/test_elements.py index 6c96e5c..1b23117 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -318,10 +318,10 @@ def test_image_excessive_alt_text_raises_exception(): def test_builds_static_select_with_options(): assert StaticSelect( - placeholder=PlainText(text="placeholder"), + placeholder="placeholder", action_id="action_id", options=[ - PlainOption(text=PlainText(text="option 1"), value="value_1"), + PlainOption(text="option 1", value="value_1"), PlainOption(text=PlainText(text="option 2"), value="value_2"), ], initial_option=PlainOption(text=PlainText(text="option 1"), value="value_1"), @@ -334,10 +334,13 @@ def test_builds_static_select_with_options(): focus_on_load=True, ).build() == { "type": "static_select", - "placeholder": {"type": "plain_text", "text": "placeholder"}, + "placeholder": {"type": "plain_text", "text": "placeholder", "emoji": True}, "action_id": "action_id", "options": [ - {"text": {"type": "plain_text", "text": "option 1"}, "value": "value_1"}, + { + "text": {"type": "plain_text", "text": "option 1", "emoji": True}, + "value": "value_1", + }, {"text": {"type": "plain_text", "text": "option 2"}, "value": "value_2"}, ], "initial_option": { @@ -1559,6 +1562,7 @@ def test_timepicker_excessive_placeholder_raises_exception(): with pytest.raises(ValidationError): TimePicker(placeholder=PlainText(text="p" * 151)) + def test_builds_fileinput(): assert FileInput( action_id="action_id", @@ -1571,6 +1575,8 @@ def test_builds_fileinput(): "max_files": 1, } + def test_fileinput_excessive_max_files_raises_exception(): with pytest.raises(ValidationError): - FileInput(max_files=11) \ No newline at end of file + FileInput(max_files=11) +