Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/rich/abc.py: 80%
5 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1from abc import ABC
4class RichRenderable(ABC):
5 """An abstract base class for Rich renderables.
7 Note that there is no need to extend this class, the intended use is to check if an
8 object supports the Rich renderable protocol. For example::
10 if isinstance(my_object, RichRenderable):
11 console.print(my_object)
13 """
15 @classmethod
16 def __subclasshook__(cls, other: type) -> bool:
17 """Check if this class supports the rich render protocol."""
18 return hasattr(other, "__rich_console__") or hasattr(other, "__rich__")
21if __name__ == "__main__": # pragma: no cover
22 from rich.text import Text
24 t = Text()
25 print(isinstance(Text, RichRenderable))
26 print(isinstance(t, RichRenderable))
28 class Foo:
29 pass
31 f = Foo()
32 print(isinstance(f, RichRenderable))
33 print(isinstance("", RichRenderable))