@property decorator doesn't raise exceptions

Peter Otten __peter__ at web.de
Wed Oct 29 05:39:04 EDT 2008


Rafe wrote:

> Thanks for the idea Peter. What confuses me is why this only happens
> to @Property (and I assume other decorator related bindings?). Does it
> have something to do with the way the class gets built? 'Normal'
> attributes will raise AttributeErrors as expected, without triggering
> __getattr__(). Considering this is a built-in decorator, it would be
> nice if this behavior was fixed if possible.

Normal attributes either exist, and then they don't raise an AttributeError,
or they don't exist, and then __getattr__() *is* triggered. The problem has
nothing to do with decorators. It is just that properties invoke custom
code, and Python currently has no way of finding out whether an
AttributeError was raised accidentally by a buggy getter or whether it is
meant to signal that the attribute wasn't found in the class  hierarchy and
now should be calculated by __getattr__().

I guess (without looking into the C source) that it could be changed to meet
your intuition but that it would complicate the implementation.

Peter




More information about the Python-list mailing list