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

Search Discussions

  • Darren Dale at Mar 13, 2011 at 4:38 am

    On Mar 12, 11:16?pm, Darren Dale 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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 13, '11 at 4:16a
activeMar 13, '11 at 4:38a
posts2
users1
websitepython.org

1 user in discussion

Darren Dale: 2 posts

People

Translate

site design / logo © 2022 Grokbase