Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

34 linhas
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))