New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPython shell swallows exceptions in certain circumstances #851
Comments
Ouch, very true! Here's the relevant code in standalone format so it's easier to put into a file for running: """
https://github.com/ipython/ipython/issues/851
"""
from traits.api import *
class Foo(HasTraits):
a = Int
def default(self):
self.remove_trait('a')
setattr(self, 'a', 42.0)
return 42.0
c = Any().as_ctrait()
c.default_value(8, default)
f = Foo()
f.add_trait('a', c) To test, use: In [1]: run bug851.py In [2]: f.a Out[2]: 0 In contrast, the expected behavior is: >>> execfile('bug851.py') >>> f.a Traceback (most recent call last): File "", line 1, in File "bug851.py", line 11, in default setattr(self, 'a', 42.0) File "/usr/lib/pymodules/python2.6/traits/trait_handlers.py", line 168, in error value ) traits.trait_errors.TraitError: The 'a' trait of a Foo instance must be an integer, but a value of 42.0 was specified. Confirming this, though it may take some digging to figure out where we are being over-aggressive. But this is pretty serious. Oddly enough, it's been there since 0.10.x (which means probably for a really long time), and nobody had ever reported the problem. But no matter, we need to fix it. |
Leave it to me to... http://imgur.com/ZLjjL On Mon, Oct 10, 2011 at 3:29 PM, Fernando Perez <
|
On Mon, Oct 10, 2011 at 1:37 PM, sccolbert
Yeah, collect your achievement badge on your way out, kiddo! ;) |
I notice from the initial vanilla Python session that it doesn't throw an error the second time you do If you do want to see where it's failing, you might want to see whether you can override the error method to raise BaseException instead of TraitError - if we've used the standard |
On Thu, Nov 10, 2011 at 1:31 PM, Thomas <
This could rear up and bite again for lots of things: properties, |
There are plenty of ways to do it, but I think the cases where it's a good We make various assumptions that certain actions won't have side effects, |
On Thu, Nov 10, 2011 at 4:39 PM, Thomas <
|
Perhaps, but:
|
On Thu, Nov 10, 2011 at 6:13 PM, Thomas <
|
The distinction is that its an exception appearing in IPython's internal If we simply limited ourself to catching AttributeError, other errors |
@sccolbert, note that you can get the behavior you're asking for, if you disable completely autocalling. Here's an example in an IPython session:
So the take-home message is: if you have code that relies on delicate attribute handling semantics, you may want to simply give up autocall altogether. You can permanently disable it in your config file, just look for 'autocall' in your default profile (create one if you don't have it with Note that we're discussing whether to change this default in the future on the dev list. But in the meantime I'm closing this, since there's really nothing we can 'fix': the fix is to turn autocall off, and we'll decide whether to do it system-wide, but users can always do it now either for just one session with |
A vanilla Python shell session:
The equivalent IPython session:
The IPython shell swallows the exception raised by the
default
function. It appears that IPython is doing subsequent getattr(obj, name) calls (which succeed in this case) after the exception is raised.The text was updated successfully, but these errors were encountered: