[IPython-dev] Extensible pretty-printing
Thu Oct 28 18:11:18 CDT 2010
On Thu, Oct 28, 2010 at 4:00 PM, Robert Kern <email@example.com> wrote:
> It's fresh. Also note that we have local modifications not in the upstream to
> support the registration of prettyprinters by the name of the type to avoid imports.
OK. Probably would be a good idea to make a little note in the file
>> One last question: we don't want anything actually *printing*, instead
>> we want an interface that *returns* strings which we'll stuff on the
>> pyout channel (an in-process version can simply take these values and
>> print them, of course).
> pretty has a pformat()-equivalent. The original pull request had already made
> that change.
>> Right now we only have a single
>> representation stored in the 'data' field. How do you think we should
>> go about the multi-field option, within the context of pretty?
> pretty does not solve that problem.
> I recommend exactly what I did in ipwx. The DisplayTrap is configured with a
> list of DisplayFormatters. Each DisplayFormatter gets a chance to decorate the
> return messaged with an additional entry, keyed by the type of the
> DisplayFormatter (probably something like 'string', 'html', 'image', etc. but
> also perhaps 'repr', 'pretty', 'mathtext'; needs some more thought). pretty
> would just be the implementation of the default string DisplayFormatter.
OK, so how do you want to proceed: do you want to reopen your pull
request (possibly rebasing it if necessary) as it was, or do you want
to go ahead and implement the above approach right away?
If the latter, I'm not sure I like the approach of passing a dict
through and letting each formatter modify it. Sate that mutates
as-it-goes tends to produce harder to understand code, at least in my
experience. Instead, we can call all the formatters in sequence and
get from each a pair of key, value. We can then insert the keys into
a dict as they come on our side (so if the storage structure ever
changes from a dict to anything else, likely the formatters can stay
unmodified). Does that sound reasonable to you?
More information about the IPython-dev