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

Brian Granger ellisonbg at gmail.com
Tue Feb 1 14:05:52 EST 2011


Fernando,

On Tue, Feb 1, 2011 at 10:36 AM, Fernando Perez <fperez.net at gmail.com> wrote:
> Hi folks,
>
> I was just thinking, before the new display infrastructure starts
> getting used too much, should we adjust our convention to use
> __repr_html__, __repr_svg__, __repr_*__ as a naming pattern instead of
> __html__, __svg__, etc?  My concern is two-fold:
>
> - the more generic names may be already in use by something else that
> doesn't quite match our 'protocol', or python may in the future
> (though this is probably needless paranoia) choose to add them.

Yes, this is important and I have spent some time thinking about this.
 The collision with other project is something to think about.  I can
say why I made the choice I did:

* Simplicity.  __html__ is easier to remember that __repr_html__.  I
want writing these methods to be like eating candy.
* There are projects that use this convention already and our usage in
compatible with theirs.  The biggest example is the __html__ method
which Pylons, mako, Jinja2, Genshi and Django supposedly support.  I
thought - wow, these guys would _love_ us if there objects were
immediately representable in IPython.

I am definitely open to the __repr_html__ style names though.  What do
other people think?

> - a more regular pattern makes it easier to collect all __repr_FOO__
> methods from an object as part of our display machinery rather than
> matching against a hard-coded list.

Yes, that is true, but it would be difficult to really use such
dynamic display logic because each FOO has to be associated with a
unique MIME type and formatter.

I was expecting this question to come up in the review of the code.
It didn't, but I am glad it is coming up now.

Cheers,

Brian

> Thoughts?
>
> f
> _______________________________________________
> 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



More information about the IPython-dev mailing list