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
Error using idlsave #988
Comments
As @takluyver reported on-list, we should catch any error here, and not assume that objects are well behaved. I would consider it a bug in AttrDict that missing attributes raises anything other than AttributeError, because it breaks extremely basic Python functionality. |
I'm not sure we should catch all errors here: objects that raise WhoKnowsWhatError on attribute access are simply broken objects, and I'm worried that having blanket exception clause here can mask other problems in the future. So I'm inclined to say we leave things as they are, and that this error simply serves as a good warning system for people of bugs in their code :) |
From Python docs for
So hasattr itself checks for arbitrary errors, rather than just AttributeError. In which case: try:
auto_rewrite = obj.rewrite
except Exception:
auto_rewrite = True is identical to if hasattr(obj, 'rewrite'):
auto_rewrite = obj.rewrite
else:
auto_rewrite = True Except the latter actually calls |
Raising other errors on attribute access is certainly awkward, but AFAIK it's not actually forbidden. Indeed, traits can do it - see #851. I think we should work gracefully with that sort of code, even if it's not ideal. |
I reread the whole thing more carefully and I agree; the approach @minrk suggested with the try/except sounds good to me. No need for a PR, go ahead and push it if you want, unless you think there's more we should look into. |
I'm going to hit the sack. @minrk, feel free to make this change, or if you've got better things to do, I'll do it tomorrow. |
Done with tests added, I'll push in a sec. |
Thanks guys, the patch fixes the issue that I originally reported. |
When analyzing the line with prefilter, we look into whether objects have a 'rewrite' attribute. While this is off-spec, we've seen in the wild objects that raise something other than AttributeError on attribute access. Now we catch all exceptions in this codepath. Closes ipython#988.
Accessing s1['dn'] should work fine within IPython like in the regular Python shell.
Until this is fixed in IPy, the workaround is to use s1.get('dn')
Using Python 2.7, IPython 0.12.dev, scipy.0.11.0.dev-7e1bb79
The text was updated successfully, but these errors were encountered: