Overriding methods in classes that use property()

Edmund Lian elian at inbrief.net
Mon Apr 22 11:45:55 EDT 2002


On Mon, 22 Apr 2002, Denis Otkidach wrote:


>EL> class C(A):
>EL>     def setVal(self, value):
>EL>         self._val = 'Huh?'
>
>Simply add one line here:
>        val = property(getVal, setVal)

Hmm... I tried this, and I get a NameError because getVal is not defined.
However, things work if I redefine class C to:

class C(A):
    def setVal(self, value):
        self._val = 'Huh?'

    def getVal(self):
        return super(C, self).getVal()

    val = property(getVal, setVal)

However, this is messy since one would have to do this for every property()
attribute in the base class that is not being overridden in a subclass!
This is *not* intuitive, *not* expected, and doesn't seem Pythonic! Seems
more like a bug to me!!!

...Edmund.






More information about the Python-list mailing list