[SciPy-Dev] Custom __repr__?

Robert Kern robert.kern at gmail.com
Thu May 6 11:50:12 EDT 2021


On Thu, May 6, 2021 at 11:10 AM Pamphile Roy <roy.pamphile at gmail.com> wrote:

> Thanks for your inputs Robert.
>
> Because these would involve extra dependencies (either matplotlib or some
> JavaScript), I would recommend starting with implementing these outside of
> scipy. You can register formatters for objects without modifying the
> objects themselves.
>
>
> We already have a soft dependency on matplotlib in *spatial* for instance
> with a few helper functions (
> https://scipy.github.io/devdocs/reference/spatial.html#plotting-helpers).
> It would be the same here, something completely optional. Plus here the
> functions are private and don’t conflict with Python’s internals.
>
>
> https://nbviewer.jupyter.org/github/ipython/ipython/blob/master/examples/IPython%20Kernel/Custom%20Display%20Logic.ipynb
>
>
> Nice examples, this is exactly this I had in mind.
>
> Well, this registration outside is quite complicated IMO… Personally, I
> think I would even prefer to mock the underlying object and add the
> *_repr_xxx* I want…
>

The user doesn't do this in each notebook. You do it once inside of an
IPython extension, and the user just %load_ext's the extension.

I think this is the kind of thing I'd like to review where it's opt-in at
first. An IPython extension is a good way to do that. Then maybe after we
get some experience using it for a while, then decide to make it always-on
by modifying the objects themselves.

-- 
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scipy-dev/attachments/20210506/ad4b43ee/attachment-0001.html>


More information about the SciPy-Dev mailing list