Jaymon / pout

Python pretty print on steroids
MIT License
29 stars 0 forks source link

subclasses of standard types should maybe print out their properties #82

Closed Jaymon closed 9 months ago

Jaymon commented 1 year ago

I have a tendency to extend standard classes quite often (eg, dict or list) and it would be really handy if these subclasses printed out extra information since they aren't vanilla standard data types.

The trigger could be isisntance(self, dict) and not self.__class__ is dict

Jaymon commented 9 months ago

I think this could be added by adding a Value.meta_value hook that is looked at in Value.string_value, it could then do something like:

<PREFIX>
    <
        <META VALUE>
    >
    <START_WRAPPER>
        <BODY_VALUE>
    <STOP_WRAPPER>

So, for a string, it would look something like:

str (7) instance at 0xNNNNNNNNN
    <
        property_name = ...
    >
    "
        foo bar
    "

The meta information wouldn't be there if there were no instance properties. Maybe the best way to do this would be to create a BuiltInValue class that implements this meta_value (default would be to just return empty string) that is extended by all the built-in value classes like DictValue etc.

Jaymon commented 9 months ago

This was added in e107df2872787e6481adc8933f84172c9aaaf5d6 with the new BuiltinValue class