Property in derived class

George Sakkis george.sakkis at gmail.com
Fri May 9 21:05:26 EDT 2008


On May 9, 5:20 pm, Joseph Turian <tur... at gmail.com> wrote:
> If I have a property in a derived class, it is difficult to override
> the get and set functions: the property's function object had early
> binding, whereas the overriden method was bound late.
> This was previously discussed:
>    http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> Could someone demonstrate how to implement the proposed solutions that
> allow the property to be declared in the abstract base class, and
> refer to a get function which is only implemented in derived classes?

Using the overridable property recipe [1], it can be written as:

class AbstractFoo(object):

    def _getFoo(self):
        raise NotImplementedError('Abstract method')
    def _setFoo(self, signals):
        raise NotImplementedError('Abstract method')

    foo = OProperty(_getFoo, _setFoo)

HTH,
George


[1] http://infinitesque.net/articles/2005/enhancing%20Python's%20property.xhtml



More information about the Python-list mailing list