Skip to content

Commit 3acb11d

Browse files
committed
Add block type enum and update block classes with type annotations
- Introduced `BlockType` enum to define standardized block types - Updated block classes to include explicit type annotations using `Literal` types - Added type hints to base block classes to improve type safety
1 parent 98cef8a commit 3acb11d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

elementary/messages/blocks.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List, Optional, Union
33

44
from pydantic import BaseModel
5+
from typing_extensions import Literal
56

67

78
class Icon(Enum):
@@ -25,6 +26,7 @@ class TextStyle(Enum):
2526

2627

2728
class BaseBlock(BaseModel):
29+
type: str
2830
pass
2931

3032

@@ -33,35 +35,41 @@ class BaseInlineTextBlock(BaseBlock):
3335

3436

3537
class TextBlock(BaseInlineTextBlock):
38+
type: Literal["text"] = "text"
3639
text: str
3740
style: Optional[TextStyle] = None
3841

3942

4043
class LinkBlock(BaseInlineTextBlock):
44+
type: Literal["link"] = "link"
4145
text: str
4246
url: str
4347

4448

4549
class IconBlock(BaseInlineTextBlock):
50+
type: Literal["icon"] = "icon"
4651
icon: Icon
4752

4853

4954
InlineBlock = Union[TextBlock, LinkBlock, IconBlock]
5055

5156

5257
class HeaderBlock(BaseBlock):
58+
type: Literal["header"] = "header"
5359
text: str
5460

5561

5662
class CodeBlock(BaseBlock):
63+
type: Literal["code"] = "code"
5764
text: str
5865

5966

6067
class DividerBlock(BaseBlock):
61-
pass
68+
type: Literal["divider"] = "divider"
6269

6370

6471
class LineBlock(BaseBlock):
72+
type: Literal["line"] = "line"
6573
inlines: List[InlineBlock]
6674
sep: str = " "
6775

@@ -71,19 +79,22 @@ class BaseLinesBlock(BaseBlock):
7179

7280

7381
class LinesBlock(BaseLinesBlock):
74-
pass
82+
type: Literal["lines"] = "lines"
7583

7684

7785
class FactBlock(BaseBlock):
86+
type: Literal["fact"] = "fact"
7887
title: LineBlock
7988
value: LineBlock
8089

8190

8291
class FactListBlock(BaseBlock):
92+
type: Literal["fact_list"] = "fact_list"
8393
facts: List[FactBlock]
8494

8595

8696
class ExpandableBlock(BaseBlock):
97+
type: Literal["expandable"] = "expandable"
8798
title: str
8899
body: List["InExpandableBlock"]
89100
expanded: bool = False

0 commit comments

Comments
 (0)