two brief question about abstractproperty

D

Darren Dale

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, nor for the case where I do:

class D(C):
pass
d=D()

Have I misunderstood the documentation? Why doesn't this raise an
error? I see the same behavior with the @abstractmethod.

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"
 
D

Darren Dale

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top