Skip to content

Conversation

@minrk
Copy link
Member

@minrk minrk commented Aug 14, 2012

rather than an alias

There are two options here:

  1. _render_traceback_ should call render_traceback
  2. any subclass that redefines render_traceback must also redefine _render_traceback_

I went with 1., which is more efficient code-wise when subclassing RemoteError
(would prevent future cases of this same mistake),
but less efficient execution-wise, because it involves an extra function call.

closes #2303

rather than an alias

There are two options here:

1. `_render_traceback_`  should *call* render_traceback
2. any subclass that redefines render_traceback must also redefine `_render_traceback_`

I went with 1., which is more efficient code-wise when subclassing RemoteError
(would prevent future cases of this same mistake),
but less efficient execution-wise, because it involves an extra function call.

closes ipython#2303
@travisbot
Copy link

This pull request fails (merged 09b440a into 289fc01).

@minrk
Copy link
Member Author

minrk commented Aug 14, 2012

Just adding a test first

@travisbot
Copy link

This pull request passes (merged dddd6d4 into 289fc01).

@fperez
Copy link
Member

fperez commented Aug 16, 2012

+1 to this approach. When a traceback is being rendered, execution is stopping anyway, so micro-optimizing to make the stack one frame shallower isn't really necessary.

Please check, however, that after this patch the traceback in various scenarios look OK. We have some fairly brittle logic in a few places that has hardcoded the 'distance' (measured in number of stack frames) between the user code and the traceback-handling code. So this extra frame may mess up that logic and need adjusting (I'm not sure it does, just asking that you check to be sure, as errors like that may not be detected in our test suite).

@bfroehle
Copy link
Contributor

What isn't clear from this whole discussion is why we have two different functions render_traceback and _render_traceback_ which are ostensibly the same. Could we not just use one name or the other. I see in #2223 a claim that render_traceback is a "real public API" but I don't see that anywhere in the source for Python 2.7 or 3.2, nor really mentioned anywhere else in IPython.

@takluyver
Copy link
Member

render_traceback() is a public API in that we haven't marked it private in
any way, so third parties might use it (for example, in a graphical
debugger). But I don't want the hook to be on render_traceback() methods,
because other libraries or frameworks might have defined that on some
exceptions, but with a different API to what we expect.

@bfroehle
Copy link
Contributor

Okay, I'll bite... the third party could just as easily have named it _render_traceback_ themselves too. Unless you want to call it _ipy_render_traceback_, I don't think you can guarantee a lack of collisions.

Anyway, my point is that render_traceback and _render_traceback_ appear to be exactly the same. Do you expect some exception class to have two different implementations of the two different methods? Certainly that would be confusing as the names are almost identical and it's not clear how they should behave differently.

@minrk
Copy link
Member Author

minrk commented Aug 18, 2012

They shouldn't be different.

render_traceback is a public method on the RemoteError class. In #2223, the notion of a generic API for custom traceback rendering in IPython was added, and under the name _render_traceback_, which is equivalent to the pre-existing method.

So the choice is:

  1. remove render_traceback as a public method, and just use _render_traceback_ (not acceptable for a backport PR)
  2. use render_traceback as the generic name
  3. keep render_traceback, and add _render_traceback_ as the generic name.

There's not a huge difference between any of these.

As @bfroehle mentioned, one further option would be for the IPython-specific method to have a more IPython-specific name, e.g. _ipython_traceback_.

@bfroehle
Copy link
Contributor

Okay, thanks for the history. I guess I'd advocate for 2 ("use render_traceback as the generic name") or some variation on ("keep render_traceback but use a more descriptive name like _ipython_traceback_").

1 is, as you point out, not acceptable for backport and the names in 3 are imho too similar.

Nevertheless, I'm okay with just merging the current pull request (i.e., 3) for the sake of expediency.

@minrk
Copy link
Member Author

minrk commented Aug 21, 2012

Shall I change _render_traceback_ to _ipython_traceback_, to give it more clarity of purpose?

@takluyver
Copy link
Member

Could do - my logic in using the more generic name was that other
interfaces (like IDEs) might want to use the same hook. There's no
particular reason for it to be specific to IPython. But render_traceback
with the underscores seems sufficiently unlikely to clash with anything
already in use purely by chance.

@bfroehle
Copy link
Contributor

I'd be happy with just a docstring on the method to describe why it exists
and when it'll get called.

@minrk
Copy link
Member Author

minrk commented Aug 22, 2012

docstring added

@travisbot
Copy link

This pull request passes (merged 417f9a9 into 289fc01).

@bfroehle
Copy link
Contributor

Thanks. Looks ok to me now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an AssertPrints context manager that makes this sort of test easy. It can't do the counting you use below, though.

@takluyver
Copy link
Member

Looks fine to me too.

minrk added a commit that referenced this pull request Aug 26, 2012
RemoteError._render_traceback_ calls self.render_traceback

rather than an alias, which can be broken by subclassing

closes #2303
@minrk minrk merged commit 58335ad into ipython:master Aug 26, 2012
minrk added a commit that referenced this pull request Aug 26, 2012
…raceback

rather than an alias

There are two options here:

1. `_render_traceback_`  should *call* render_traceback
2. any subclass that redefines render_traceback must also redefine `_render_traceback_`

I went with 1., which is more efficient code-wise when subclassing RemoteError
(would prevent future cases of this same mistake),
but less efficient execution-wise, because it involves an extra function call.

closes #2303
minrk added a commit that referenced this pull request Aug 27, 2012
adjust division error message checking to account for Python 3

fixes Python3-specific typo introduced #2305
minrk added a commit that referenced this pull request Aug 27, 2012
…for Python 3

fix Python3-specific typo introduced #2305
minrk added a commit that referenced this pull request Sep 1, 2012
…raceback

rather than an alias

There are two options here:

1. `_render_traceback_`  should *call* render_traceback
2. any subclass that redefines render_traceback must also redefine `_render_traceback_`

I went with 1., which is more efficient code-wise when subclassing RemoteError
(would prevent future cases of this same mistake),
but less efficient execution-wise, because it involves an extra function call.

closes #2303
minrk added a commit that referenced this pull request Sep 1, 2012
…for Python 3

fix Python3-specific typo introduced #2305
@minrk minrk deleted the render_traceback branch March 31, 2014 23:36
yarikoptic added a commit to yarikoptic/ipython that referenced this pull request May 2, 2014
* commit 'rel-0.13-33-gcfc5692': (33 commits)
  Backport PR ipython#2347: adjust division error message checking to account for Python 3
  Backport PR ipython#2305: RemoteError._render_traceback_ calls self.render_traceback
  Backport PR ipython#2280: fix SSH passwordless check for OpenSSH
  Backport PR ipython#2270: SSHLauncher tweaks
  Backport PR ipython#2261: Fix: longest_substr([]) -> ''
  Backport PR ipython#2250: fix html in notebook example
  Backport PR ipython#2235: remove spurious print statement from setupbase.py
  fixup
  Backport PR ipython#2223: Custom tracebacks
  Backport PR ipython#2214: use KernelApp.exec_lines/files in IPEngineApp
  Backport PR ipython#2212: catch errors in markdown javascript
  Backport PR ipython#2194: clean nan/inf in json_clean
  Backport PR ipython#2177: remove numpy install from travis/tox scripts
  Backport PR ipython#2169: ipdb: pdef, pdoc, pinfo magics all broken
  Backport PR ipython#2186: removed references to h5py dependence in octave magic documentation
  Backport PR ipython#2185: added test for %store, fixed storemagic
  Backport PR ipython#2170: Fix tab completion with IPython.embed_kernel().
  Backport PR ipython#2163: fix 'remote_profie_dir' typo in SSH launchers
  Backport PR ipython#2117: use explicit url in notebook example
  Backport PR ipython#2126: ipcluster broken with any batch (PBS/LSF/SGE)
  ...
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
RemoteError._render_traceback_ calls self.render_traceback

rather than an alias, which can be broken by subclassing

closes ipython#2303
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
adjust division error message checking to account for Python 3

fixes Python3-specific typo introduced ipython#2305
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

remote tracebacks broken since 952d0d6 (PR #2223)

5 participants