MCPcopy Index your code
hub / github.com/slackapi/python-slack-sdk / TextObject

Class TextObject

slack_sdk/models/blocks/basic_components.py:14–70  ·  view source on GitHub ↗

The interface for text objects (types: plain_text, mrkdwn)

Source from the content-addressed store, hash-verified

12
13
14class TextObject(JsonObject):
15 """The interface for text objects (types: plain_text, mrkdwn)"""
16
17 attributes = {"text", "type", "emoji"}
18 logger = logging.getLogger(__name__)
19
20 def _subtype_warning(self):
21 warnings.warn(
22 "subtype is deprecated since slackclient 2.6.0, use type instead",
23 DeprecationWarning,
24 )
25
26 @property
27 def subtype(self) -> Optional[str]:
28 return self.type
29
30 @classmethod
31 def parse(
32 cls,
33 text: Union[str, Dict[str, Any], "TextObject"],
34 default_type: str = "mrkdwn",
35 ) -> Optional["TextObject"]:
36 if not text:
37 return None
38 elif isinstance(text, str):
39 if default_type == PlainTextObject.type:
40 return PlainTextObject.from_str(text)
41 else:
42 return MarkdownTextObject.from_str(text)
43 elif isinstance(text, dict):
44 d = copy.copy(text)
45 t = d.pop("type")
46 if t == PlainTextObject.type:
47 return PlainTextObject(**d)
48 else:
49 return MarkdownTextObject(**d)
50 elif isinstance(text, TextObject):
51 return text
52 else:
53 cls.logger.warning(f"Unknown type ({type(text)}) detected when parsing a TextObject")
54 return None
55
56 def __init__(
57 self,
58 text: str,
59 type: Optional[str] = None,
60 subtype: Optional[str] = None,
61 emoji: Optional[bool] = None,
62 **kwargs,
63 ):
64 """Super class for new text "objects" used in Block kit"""
65 if subtype:
66 self._subtype_warning()
67
68 self.text = text
69 self.type = type if type else subtype
70 self.emoji = emoji
71

Callers 2

legacyFunction · 0.90
issue_868.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected