@property decorator doesn't raise exceptions

greg greg at cosc.canterbury.ac.nz
Sun Oct 26 02:23:46 CEST 2008

Rafe wrote:

> The docs seem to suggest this is impossible:
> "Called when an attribute lookup has not found the attribute in the
> usual places (i.e. it is not an instance attribute nor is it found in
> the class tree for self).

Getting an AttributeError is the way that the interpreter
machinery tells that the attribute wasn't found. So when
your property raises an AttributeError, this is
indistinguishable from the case where the property wasn't
there at all.

To avoid this you would have to raise some exception
that doesn't derive from AttributeError.


More information about the Python-list mailing list