all Python 3abcfunction
abc.abstractmethod
abstract classes
A decorator marking a method abstract; subclasses must override it.
Syntax
@abc.abstractmethod
The decorator enforces nothing on its own — it just sets the __isabstractmethod__ flag on the function; refusing instantiation is the job of the ABCMeta metaclass. In a class that uses neither ABC nor ABCMeta the mark is silently ignored and the "abstract" method stays perfectly callable. When stacking decorators, abstractmethod must be the innermost one, with @classmethod or @property sitting above it.
Examples
import abc
class B(abc.ABC):
@abc.abstractmethod
def f(self): ...
print('f' in B.__abstractmethods__) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy