two brief question about abstractproperty

Discussion in 'Python' started by Darren Dale, Mar 13, 2011.

  1. Darren Dale

    Darren Dale Guest

    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"
    Darren Dale, Mar 13, 2011
    #1
    1. Advertising

  2. Darren Dale

    Darren Dale Guest

    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.
    Darren Dale, Mar 13, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adam Barr
    Replies:
    1
    Views:
    492
  2. Steve
    Replies:
    13
    Views:
    1,008
    Juan T. Llibre
    Sep 5, 2005
  3. Adam Barr
    Replies:
    6
    Views:
    390
    Adam Barr
    Feb 27, 2004
  4. Irving Kimura
    Replies:
    0
    Views:
    398
    Irving Kimura
    Dec 16, 2003
  5. Tom Brown

    Re: A brief question.

    Tom Brown, Jul 3, 2005, in forum: Python
    Replies:
    46
    Views:
    990
    Michael Hudson
    Jul 15, 2005
Loading...

Share This Page