Skip to content
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 another case of exception swallowing from PyObject_GenericGetAttr #960

Merged
merged 3 commits into from
Mar 26, 2020

Conversation

mdickinson
Copy link
Member

When an attribute is looked up on a CTrait object, None is returned on failed lookup, regardless of the actual exception that was raised. This means that (for example) logic errors from a CTrait method will be silenced.

This PR changes the behaviour to only return None if the attribute lookup raises AttributeError, and to propagate any other exception.

This is the cTrait analog to #959 for CHasTraits.

Along with #959, this fixes #946.

@mdickinson
Copy link
Member Author

Here's an example of a (desirable, IMO) behaviour change due to this PR

On master:

>>> from traits.api import *
>>> ct = CTrait(0)
>>> ct.set_default_value(DefaultValue.list_copy, 1j)  # Bad: 2nd argument should be a list
>>> ct.default
>>> ct.default is None
True

On this branch:

>>> from traits.api import *
>>> ct = CTrait(0)
>>> ct.set_default_value(DefaultValue.list_copy, 1j)
>>> ct.default
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mdickinson/Enthought/ETS/traits/traits/ctrait.py", line 71, in default
    return value[:]
TypeError: 'complex' object is not subscriptable

OTOH, with DefaultValue.dict_copy in place of DefaultValue.list_copy, the exception gets swallowed again, because an AttributeError is raised. :-(

Copy link
Contributor

@corranwebster corranwebster left a comment

Choose a reason for hiding this comment

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

LGTM

@mdickinson mdickinson merged commit e7bd263 into master Mar 26, 2020
@mdickinson mdickinson deleted the fix/swallowed-getattr-error2 branch March 26, 2020 13:39
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.

Don't allow any exception in PyObject_GenericGetAttr calls
2 participants