Define Font.__repr__() to be printed in the doc in a readable format (#5904)

* Define Font.__repr__() to be printed in the doc in a readable format

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Yuichiro Tachibana (Tsuchiya) 2023-10-16 10:10:28 +09:00 committed by GitHub
parent c4ba832b31
commit 891d42e9ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Define Font.__repr__() to be printed in the doc in a readable format

View File

@ -40,6 +40,12 @@ class Font:
def __eq__(self, other: Font) -> bool:
return self.name == other.name and self.stylesheet() == other.stylesheet()
def __repr__(self) -> str:
klass = type(self)
class_repr = klass.__module__ + "." + klass.__qualname__
attrs = ", ".join([k + "=" + repr(v) for k, v in self.__dict__.items()])
return f"<{class_repr} ({attrs})>"
class GoogleFont(Font):
def __init__(self, name: str, weights: Iterable[int] = (400, 600)):