Apparently when an AttributeError is raised from a property of a QObject then the traceback includes a different AttributeError instead namely one referring to the property itself.
Running the following code
import sys
from PyQt4 import QtCore
class MyObject(QtCore.QObject):
def __init__(self, parent=None):
super(MyObject, self).__init__(parent)
@property
def invalid_property(self):
raise AttributeError('test')
# raise TypeError('test')
def invalid_method(self):
raise AttributeError('test')
obj = MyObject()
obj.invalid_property
# obj.invalid_method()
gives
Traceback (most recent call last):
File "test.py", line 19, in <module>
obj.invalid_property
AttributeError: 'MyObject' object has no attribute 'invalid_property'
That is the original AttributeError is replaced by a different one in the traceback.
I tried the same raising a TypeError which works just fine, as well as raising the AttributeError from a conventional method which works fine too.
If I inherit from object instead of QObject then the original AttributeError appears in the traceback too.
So what's happening here? Is a different AttributeError raised or is the original one's message just altered? And why does this happen? Is this a bug or intended behavior?
Related: