Skip to content

Custom tracebacks #2223

Merged
merged 5 commits into from Jul 31, 2012

3 participants

@takluyver
IPython member

Rather than special casing IPython.parallel errors (which led to issue #2221), this adds a simple API where exception classes can offer a custom traceback, by defining a _render_traceback_(self) method.

It also adds some documentation on how third parties can integrate packages with IPython. 'Configuration & customisation' seemed the most natural home for this.

We should remember to close #2221 when we merge this - I forgot to put it in a commit message.

@minrk minrk and 1 other commented on an outdated diff Jul 30, 2012
IPython/parallel/error.py
"""render traceback to a list of lines"""
return (self.traceback or "No traceback available").splitlines()
+
+ # Previous name retained for backwards compatibility.
+ render_traceback = _render_traceback_
@minrk
IPython member
minrk added a note Jul 30, 2012

I would reverse this alias, because render_traceback is a real public API (not deprecated), and _render_traceback_ is the custom IPython-specific semi-private API.

I know there's no real difference, but I think this way gives the wrong idea.

@takluyver
IPython member
takluyver added a note Jul 30, 2012

OK, I've done that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@minrk
IPython member
minrk commented Jul 30, 2012

I know it's technically adding a new API, but it seems like we should include this in 0.13.1 to avoid the inappropriate imports. Do you agree?

@takluyver
IPython member

Once we're confident it works, I think the flaw is significant enough to warrant backporting the fix, yes.

@minrk
IPython member
minrk commented Jul 30, 2012
@takluyver
IPython member

A subprocess test turned out to be pretty easy. I'm running test_pr now.

@minrk
IPython member
minrk commented Jul 30, 2012

Test results for commit 464d50a merged into master
Platform: darwin

  • python2.6: OK (libraries not available: cython matplotlib oct2py pygments pymongo qt rpy2 tornado wx wx.aui)
  • python2.7: OK (libraries not available: oct2py rpy2 wx wx.aui)
  • python3.2: OK (libraries not available: cython matplotlib oct2py pygments pymongo qt rpy2 wx wx.aui)

Not available for testing:

@minrk
IPython member
minrk commented Jul 30, 2012

Great, then I think it should be good to go.

@takluyver
IPython member

I'll leave it overnight (my time) in case anyone else wants to look at it, then I'll merge tomorrow. Thanks for the review.

@Carreau Carreau and 1 other commented on an outdated diff Jul 31, 2012
docs/source/config/integrating.txt
+==============
+
+To change the attributes displayed by tab-completing your object, define a
+``__dir__(self)`` method for it. For more details, see the documentation of the
+built-in `dir() function <http://docs.python.org/library/functions.html#dir>`_.
+
+Rich display
+============
+
+The notebook and the Qt console can display richer representations of objects.
+To use this, you can define any of a number of ``_repr_*_()`` methods. Note that
+these are surrounded by single, not double underscores.
+
+Both the notebook and the Qt console can display ``svg``, ``png`` and ``jpeg``
+representations. The notebook can also display ``html``, ``javascript``,
+``json`` and ``latex``. If the methods don't exist, or return ``None``, it falls
@Carreau
IPython member
Carreau added a note Jul 31, 2012

Out of curiosity, is there any example of something using display_json?

@takluyver
IPython member
takluyver added a note Jul 31, 2012

No, and it seems it doesn't actually work in the notebook. I'll take it out of the list.

@Carreau
IPython member
Carreau added a note Jul 31, 2012

we do have a display_json in IPython.display do we want to write a warning that not many frontend support it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@takluyver
IPython member

I've updated the docs.

@Carreau
IPython member
Carreau commented Jul 31, 2012

I'm ok with merging this.

About json, what is/was the use of it ?

@takluyver
IPython member

OK, I'll merge this now. Thanks.

I'm not sure about displaying json, but I think maybe it's the future tense we need - what will be the use of it?

@takluyver takluyver merged commit 06c27d8 into ipython:master Jul 31, 2012
@Carreau
IPython member
Carreau commented Jul 31, 2012

hum... to exchange data with widget, maybe, but then i wouldn't call it display_ ...
we'll see.

@minrk
IPython member
minrk commented Jul 31, 2012
@minrk minrk added a commit that referenced this pull request Aug 4, 2012
@minrk minrk Backport PR #2223: Custom tracebacks
Rather than special casing IPython.parallel errors (which led to issue #2221), this adds a simple API where exception classes can offer a custom traceback, by defining a `_render_traceback_(self)` method.

It also adds some documentation on how third parties can integrate packages with IPython. 'Configuration & customisation' seemed the most natural home for this.

We should remember to close #2221 when we merge this - I forgot to put it in a commit message.
952d0d6
@minrk minrk added a commit that referenced this pull request Sep 1, 2012
@minrk minrk Backport PR #2223: Custom tracebacks
Rather than special casing IPython.parallel errors (which led to issue #2221), this adds a simple API where exception classes can offer a custom traceback, by defining a `_render_traceback_(self)` method.

It also adds some documentation on how third parties can integrate packages with IPython. 'Configuration & customisation' seemed the most natural home for this.

We should remember to close #2221 when we merge this - I forgot to put it in a commit message.
d167140
@yarikoptic yarikoptic added a commit to yarikoptic/ipython that referenced this pull request May 2, 2014
@yarikoptic yarikoptic Merge commit 'rel-0.13-33-gcfc5692' into debian-01X
* commit 'rel-0.13-33-gcfc5692': (33 commits)
  Backport PR #2347: adjust division error message checking to account for Python 3
  Backport PR #2305: RemoteError._render_traceback_ calls self.render_traceback
  Backport PR #2280: fix SSH passwordless check for OpenSSH
  Backport PR #2270: SSHLauncher tweaks
  Backport PR #2261: Fix: longest_substr([]) -> ''
  Backport PR #2250: fix html in notebook example
  Backport PR #2235: remove spurious print statement from setupbase.py
  fixup
  Backport PR #2223: Custom tracebacks
  Backport PR #2214: use KernelApp.exec_lines/files in IPEngineApp
  Backport PR #2212: catch errors in markdown javascript
  Backport PR #2194: clean nan/inf in json_clean
  Backport PR #2177: remove numpy install from travis/tox scripts
  Backport PR #2169: ipdb: pdef, pdoc, pinfo magics all broken
  Backport PR #2186: removed references to h5py dependence in octave magic documentation
  Backport PR #2185: added test for %store, fixed storemagic
  Backport PR #2170: Fix tab completion with IPython.embed_kernel().
  Backport PR #2163: fix 'remote_profie_dir' typo in SSH launchers
  Backport PR #2117: use explicit url in notebook example
  Backport PR #2126: ipcluster broken with any batch (PBS/LSF/SGE)
  ...
fc7c7f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.