Python Data Classes instances also include a string representation method, but its result isn't really sufficient for pretty printing purposes when classes have more than a few fields and/or longer field values.
Basically I'm looking for a way to customize the default dataclasses string representation routine or for a pretty-printer that understands data classes and prints them prettier.
So, it's just a small customization I have in mind: adding a line break after each field while indenting lines after the first one.
For example, instead of
x = InventoryItem('foo', 23)
print(x) # =>
InventoryItem(name='foo', unit_price=23, quantity_on_hand=0)
I want to get a string representation like this:
x = InventoryItem('foo', 23)
print(x) # =>
InventoryItem(
name='foo',
unit_price=23,
quantity_on_hand=0
)
Or similar. Perhaps a pretty-printer could get even fancier, such as aligning the =
assignment characters or something like that.
Of course, it should also work in a recursive fashion, e.g. fields that are also dataclasses should be indented more.