[IPython-dev] New display methods, should we fine-tune our naming decision?

MinRK benjaminrk at gmail.com
Tue Feb 1 20:13:16 EST 2011


On Tue, Feb 1, 2011 at 16:21, Brian Granger <ellisonbg at gmail.com> wrote:

> On Tue, Feb 1, 2011 at 2:24 PM, Robert Kern <robert.kern at gmail.com> wrote:
> > On 2/1/11 1:32 PM, Alex Gaynor wrote:
> >
> >> Be careful with __html__ (Django doesn't support it, I think all the
> others you
> >> named do), it's not really intended to handle HTML formatting of an
> object, but
> >> really just manage whether or not it's supposed to be escaped or not.
> >
> > Right. It's a tool for frameworks/template libraries to implement
> internal
> > SafeString/Markup/whatever objects, not for application/library authors
> to make
> > HTML representations of their model objects. If a Jinja2 user is viewing
> a
> > Markup object in IPython, they want to see "Markup(u'<p>foo</p>')", not
> an
> > HTML-formatted "foo". The HTMLFormatter's behavior is undesirable, and I
> think
> > this is a good reason to avoid using __html__, at least.
>
> OK, this is very useful information.  Let's find a different naming
> convention for these.  What do people prefer?
>

My vote might be for '__htmlrepr__',
I like 'htmlrepr' more than 'repr_html' because it's 'html representation'
not 'representation html', despite the tab-completion friendliness of the
latter pattern.

or we could use a mimetypes method that lets developers pick their own
methods by returning a dict:

def __mimetypes__(self):
      return { 'text/html' : self.htmlify,
          'image/png' : lambda self: self.as_image(type='png'),
      }



>
> Also, Robert, do you think we need to change the priority of the
> special method/print function logic?
>
> Brian
>
> > --
> > Robert Kern
> >
> > "I have come to believe that the whole world is an enigma, a harmless
> enigma
> >  that is made terrible by our own mad attempt to interpret it as though
> it had
> >  an underlying truth."
> >   -- Umberto Eco
> >
> > _______________________________________________
> > IPython-dev mailing list
> > IPython-dev at scipy.org
> > http://mail.scipy.org/mailman/listinfo/ipython-dev
> >
>
>
>
> --
> Brian E. Granger, Ph.D.
> Assistant Professor of Physics
> Cal Poly State University, San Luis Obispo
> bgranger at calpoly.edu
> ellisonbg at gmail.com
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20110201/aec6da02/attachment.html>


More information about the IPython-dev mailing list