properties & exceptions

Chuck Esterbrook ChuckEsterbrook at
Mon Apr 14 08:24:54 CEST 2003

On Sunday 13 April 2003 05:30 pm, Saveen Reddy [MSFT] wrote:
> I was suprised by a python behavior I saw concerning exceptions thrown
> when accessing a class through a property. Essentially, I am seeing an
> unexpected exception, one that implies the property doesn't exist when
> in fact it does. I haven't found any docs that explain this behavior
> and so my questions are (1) is this behavior "by-design"? and (2)
> Besides not using properties, is there a workaround?

On Sunday 13 April 2003 06:05 pm, Mike C. Fletcher wrote:
> Any chance you don't have a __metaclass__ = type declaration?  You
> don't subclass object in the example you cite, and without one of
> those properties just don't work.

I reported this behavior as a bug some time ago, but was told it wasn't 
a bug because I didn't subclass object. However, it's very deceptive 
and Python usually either works or gives a meaningful exception, so 
let's call it a "flaw". For example, if properties just don't work in 
classes not derived from object, then the Pythonic thing to do would be 
to raise a CannotUsePropertiesInOldClasses exception when trying to 
create them.

In any case, the reason I'm replying here is to report that in Python 
2.3a2, the bug, er I mean the flaw, has been fixed: exceptions in 
properties propagate correctly regardless of the base classes. That's 
great since it will reduce confusion. Plus, I like to use properties in 
wxPython subclasses, but cannot currently change wxObject to inherit 


More information about the Python-list mailing list