abc.abstractproperty()

@abc.abstractproperty(fget=None, fset=None, fdel=None, doc=None)

A subclass of the built-in property(), indicating an abstract property.

Using this function requires that the class’s metaclass is ABCMeta or is derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods and properties are overridden. The abstract properties can be called using any of the normal ‘super’ call mechanisms.

This special case is deprecated, as the property() decorator is now correctly identified as abstract when applied to an abstract method:

class C(metaclass=ABCMeta):
    @property
    @abstractmethod
    def my_abstract_property(self):
        ...

The above example defines a read-only property; you can also define a read-write abstract property by appropriately marking one or more of the underlying methods as abstract:

class C(metaclass=ABCMeta):
    @property
    def x(self):
        ...

    @x.setter
    @abstractmethod
    def x(self, val):
        ...

If only some components are abstract, only those components need to be updated to create a concrete property in a subclass:

class D(C):
    @C.x.setter
    def x(self, val):
        ...

Deprecated since version 3.3: It is now possible to use property, property.getter(), property.setter() and property.deleter() with abstractmethod(), making this decorator redundant.

doc_python
2016-10-07 17:26:05
Comments
Leave a Comment

Please login to continue.