[Python-Dev] Attribute error: providing type name

Nick Coghlan ncoghlan at gmail.com
Sun Nov 30 22:50:33 CET 2008

Filip Gruszczyński wrote:
> I have done some testing and it seems, that it might not be Python
> problem. Well, when I use only pure Python objects, I get really nice
> description of the object (which means the type). But I am using PyQt
> and it seems, that when an object is subclassing QObject (or possibly
> some other class from qt, that can be not derived from QObject) it can
> only display information about the name of the function. PyQt are
> python bindings for C++ qt library. Can this be the reason for not
> displaying type of the object?

Yeah, any time someone implements their own attribute lookup process for
a class (be it via __getattr__, __getattribute__ or the C equivalents),
it is up to the reimplementation to appropriately format their error
message if they raise AttributeError directly.

This could possibly be made easier to do correctly via a specific
AttributeError class method (also exposed through the C API) that
accepted a type object and an attribute name and then produced a nicely
formatted error message the way the builtin types do.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list