diff --git a/docs/source/config/integrating.rst b/docs/source/config/integrating.rst index 07429ef..83454a1 100644 --- a/docs/source/config/integrating.rst +++ b/docs/source/config/integrating.rst @@ -26,15 +26,17 @@ Rich display Custom methods ---------------------- + IPython can display richer representations of objects. -To do this, you can define ``_ipython_display_()``, or any of a number of -``_repr_*_()`` methods. +To do this, you can define ``_ipython_display_()``, or any of a number of +``_repr_*_()`` methods. Note that these are surrounded by single, not double underscores. + .. list-table:: Supported ``_repr_*_`` methods :widths: 20 15 15 15 :header-rows: 1 - + * - Format - REPL - Notebook @@ -76,14 +78,24 @@ Note that these are surrounded by single, not double underscores. - ? - ? -If the methods don't exist, or return ``None``, the standard ``repr()`` is used. +If the methods don't exist, the standard ``repr()`` is used. +If a method exists and returns ``None``, it is treated the same as if it does not exist. +In general, *all* available formatters will be called when an object is displayed, +and it is up to the UI to select which to display. +A given formatter should not generally change its output based on what other formats are available - +that should be handled at a different level, such as the :class:`~.DisplayFormatter`, or configuration. + +``_repr_*_`` methods should *return* data of the expected format and have no side effects. +For example, ``_repr_html_`` should return HTML as a `str` and ``_repr_png_`` should return PNG data as `bytes`. + +If you wish to take control of display via your own side effects, use ``_ipython_display_()``. For example:: class Shout(object): def __init__(self, text): self.text = text - + def _repr_html_(self): return "