MCPcopy
hub / github.com/Textualize/rich / __call__

Method __call__

rich/highlighter.py:20–39  ·  view source on GitHub ↗

Highlight a str or Text instance. Args: text (Union[str, ~Text]): Text to highlight. Raises: TypeError: If not called with text or str. Returns: Text: A test instance with highlighting applied.

(self, text: Union[str, Text])

Source from the content-addressed store, hash-verified

18 """Abstract base class for highlighters."""
19
20 def __call__(self, text: Union[str, Text]) -> Text:
21 """Highlight a str or Text instance.
22
23 Args:
24 text (Union[str, ~Text]): Text to highlight.
25
26 Raises:
27 TypeError: If not called with text or str.
28
29 Returns:
30 Text: A test instance with highlighting applied.
31 """
32 if isinstance(text, str):
33 highlight_text = Text(text)
34 elif isinstance(text, Text):
35 highlight_text = text.copy()
36 else:
37 raise TypeError(f"str or Text instance required, not {text!r}")
38 self.highlight(highlight_text)
39 return highlight_text
40
41 @abstractmethod
42 def highlight(self, text: Text) -> None:

Callers

nothing calls this directly

Calls 3

highlightMethod · 0.95
TextClass · 0.85
copyMethod · 0.45

Tested by

no test coverage detected