m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
890 B

6 months ago
  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 pip._vendor.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))