samedi 16 juillet 2016

property getter not called

First of all, this is my code;

from abc import ABCMeta
from abc import abstractproperty

class A(object):
    __metaclass__ = ABCMeta

    @abstractproperty
    def example_property(self):
        pass

class B(A):
    @property
    def example_property(self):
        return 'This is an '

b = B()
print(b.example_property + ' example!')

B is instantiated by working over A.__subclasses__() since there are some more classes that inherit from A like B.

Either I completely misunderstond properties, or something is going wrong. When the print statement is executed, I get

TypeError: unsupported operand type(s) for +: 'property' and 'str'

Any help is well appreciated!

Aucun commentaire:

Enregistrer un commentaire