-
Notifications
You must be signed in to change notification settings - Fork 85
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
Fix exception swallowing by Trait attribute access #959
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I assume we have a text case somewhere where AttributeError
is correctly raised by the regular access machinery and processing carries on.
I'll double check. But I'd be surprised if we didn't: this should be a very common case. |
Hmm. Lots of occurrences (I count 35 cases from running the test suite), but nothing that's directly exercising this case. I'll add another test. |
Codecov Report
@@ Coverage Diff @@
## master #959 +/- ##
==========================================
+ Coverage 73.05% 73.16% +0.10%
==========================================
Files 51 51
Lines 6514 6507 -7
Branches 1309 1308 -1
==========================================
+ Hits 4759 4761 +2
+ Misses 1363 1352 -11
- Partials 392 394 +2
Continue to review full report at Codecov.
|
Additional tests look good 👍 |
When doing
obj.attr_name
on aHasTraits
objectobj
, ifattr_name
doesn't appear in either the class or instance dictionaries, Traits next tries to look it up as a regular Python attribute (via thePyObject_GenericGetAttr
C-API function). If that lookup fails with an exception of any kind, the exception is swallowed and Traits then moves on to try the general prefix-trait machinery. In effect, there's a bareexcept
here, but at C level.This PR modifies the behaviour to replace the bare
except
with anexcept AttributeError
, so that exceptions other thanAttributeError
will no longer be swallowed.The fix itself is easy. Writing a regression test that worked was ... more interesting.
This fixes one case of #946.