abc ¶
Abstract Base Classes (ABCs) according to PEP 3119.
Classes:
-
ABC
–Helper class that provides a standard way to create an ABC using
-
abstractclassmethod
–A decorator indicating abstract classmethods.
-
abstractproperty
–A decorator indicating abstract properties.
-
abstractstaticmethod
–A decorator indicating abstract staticmethods.
Functions:
-
abstractmethod
–A decorator indicating abstract methods.
-
update_abstractmethods
–Recalculate the set of abstract methods of an abstract class.
ABC ¶
Helper class that provides a standard way to create an ABC using inheritance.
abstractclassmethod ¶
abstractclassmethod(callable)
Bases: classmethod
A decorator indicating abstract classmethods.
Deprecated, use 'classmethod' with 'abstractmethod' instead:
class C(ABC):
@classmethod
@abstractmethod
def my_abstract_classmethod(cls, ...):
...
Source code in src/sake/abc.py
46 47 48 |
|
abstractproperty ¶
Bases: property
A decorator indicating abstract properties.
Deprecated, use 'property' with 'abstractmethod' instead:
class C(ABC):
@property
@abstractmethod
def my_abstract_property(self):
...
abstractstaticmethod ¶
abstractstaticmethod(callable)
Bases: staticmethod
A decorator indicating abstract staticmethods.
Deprecated, use 'staticmethod' with 'abstractmethod' instead:
class C(ABC):
@staticmethod
@abstractmethod
def my_abstract_staticmethod(...):
...
Source code in src/sake/abc.py
66 67 68 |
|
abstractmethod ¶
abstractmethod(funcobj)
A decorator indicating abstract methods.
Requires that the metaclass is ABCMeta or derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods are overridden. The abstract methods can be called using any of the normal 'super' call mechanisms. abstractmethod() may be used to declare abstract methods for properties and descriptors.
Usage:
class C(metaclass=ABCMeta):
@abstractmethod
def my_abstract_method(self, arg1, arg2, argN):
...
Source code in src/sake/abc.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
update_abstractmethods ¶
update_abstractmethods(cls)
Recalculate the set of abstract methods of an abstract class.
If a class has had one of its abstract methods implemented after the class was created, the method will not be considered implemented until this function is called. Alternatively, if a new abstract method has been added to the class, it will only be considered an abstract method of the class after this function is called.
This function should be called before any use is made of the class, usually in class decorators that add methods to the subject class.
Returns cls, to allow usage as a class decorator.
If cls is not an instance of ABCMeta, does nothing.
Source code in src/sake/abc.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|