[PyQt] Python property in QObject masks AttributeErrors

Phil Thompson phil at riverbankcomputing.com
Mon Apr 18 22:18:20 BST 2011


On Mon, 18 Apr 2011 14:07:13 +0200, Benjamin Kloster
<benjamin.kloster at videlco.eu> wrote:
> Hi everyone,
> twice now I've stumbled over a subtle bug when subclassing QObject. When
> the getter of a python property raises an AttributeError for any
> attribute or object, PyQt seems to reraise this error improperly,
> clearing the traceback and often reporting a false object type and
> attribute name. See the attached script for a minimal example.
> 
> Regards,
> Ben

It's working as it should.

If the getter raises an AttributeError Python then calls any __getattr__
method. If there is no method then the exception raised by the getter is
propagated. If there is a __getattr__ then the getter exception is
discarded and the exception raised by __getattr__ is propagated.

QObject implements __getattr__ so the exception raised by the failure of
QtCore.iDontExist is discarded. The exception that QObject.__getattr__
raises is what you are seeing.

Phil


More information about the PyQt mailing list