您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

34 行
878 B

  1. from abc import ABC
  2. class RichRenderable(ABC):
  3. """An abstract base class for Rich renderables.
  4. Note that there is no need to extend this class, the intended use is to check if an
  5. object supports the Rich renderable protocol. For example::
  6. if isinstance(my_object, RichRenderable):
  7. console.print(my_object)
  8. """
  9. @classmethod
  10. def __subclasshook__(cls, other: type) -> bool:
  11. """Check if this class supports the rich render protocol."""
  12. return hasattr(other, "__rich_console__") or hasattr(other, "__rich__")
  13. if __name__ == "__main__": # pragma: no cover
  14. from rich.text import Text
  15. t = Text()
  16. print(isinstance(Text, RichRenderable))
  17. print(isinstance(t, RichRenderable))
  18. class Foo:
  19. pass
  20. f = Foo()
  21. print(isinstance(f, RichRenderable))
  22. print(isinstance("", RichRenderable))