Use different __rich_console__
implementations depending on method that calls rich.print()
#2771
Unanswered
anna-charlotte
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have a class
MyDoc(pydantic.BaseModel)
:and would like to implement the following methods:
.summary()
to show a detailed summary in tabular or tree like structure including information about theMyDoc
instance attributes and values. To do so I create at = rich.tree.Tree
including the information of my obj. Additionally I implement__rich_console__()
where I explicitly define the tabular structure I want to display. Then I can callrich.print(t)
output:
Wanted output:
But, actual output:
Problem:
Since I overwrite
__rich_console__()
for 1., the pydantic pretty print is being overwritten.It seems that in both cases the
__rich_console__
function is called. Is it possible to call one function as__rich_console__
when rich.print is called frompretty_print()
and a different rich_console function when being called from.summary()
?Beta Was this translation helpful? Give feedback.
All reactions