two brief question about abstractproperty

Darren Dale dsdale24 at gmail.com
Sat Mar 12 23:38:26 EST 2011


On Mar 12, 11:16 pm, Darren Dale <dsdal... at gmail.com> wrote:
> I've been reading PEP 3119 and the documentation for ABCs in the
> python documentation. According to the PEP, the following should yield
> an error, because the abstract property has not been overridden:
>
> import abc
> class C:
>     __metaclass__ = abc.ABCMeta
>     @abc.abstractproperty
>     def x(self):
>         return 1
> c=C()
>
> but an error is not raised

I guess the problem was not using the appropriate syntax for python 3:

class C(metaclass=abc.ABCMeta):
    ...

> Also, why isn't it possible to declare an abstract read/write property
> with the decorator syntax:
>
> class C:
>     __metaclass__ = abc.ABCMeta
>     @abc.abstractproperty
>     def x(self):
>         pass
>     @x.setter
>     def x(self, val):
>         "this is also abstract"

It seems like this syntax should be possible, that instantiation would
check that if the C.x is an abstract property and the x.setter has
been specified, then subclasses of C need to specify a setter before
they can be instantiated.



More information about the Python-list mailing list