[Tutor] now new style properties and inheritance

Arthur Siegel ajs@ix.netcom.com
Sun, 7 Jul 2002 13:30:21 -0400


Thought I'd share more of my new style class 
explorations - and ask for any insights I may 
be missing.

An unexpected (to me) twist in the use of properties.
with inheritance. It seems that the property declaration
must be redeclared when a method in overridden a sub-class.

>>> class A(object):
            def get_prop(self):
                  print "A's property"
            prop= property(get_prop)
>>> class B(A):
            def get_prop(self):
                 print "B's property"
>>> a=A()
>>> a.prop
A's property
>>> b=B()
>>> b.prop
A's property

But -

>>> class B(A):
             def get_prop(self):
                   print "B's property"
              prop = property(get_prop)
>>> a=A()
>>> a.prop
A's property
>>> b=B()
>>> b.prop
B's property

New style classes, I am finding, are indeed newer than
I had imagined.

Am I missing something, for a change.

Art