CKTIS / Python
abc.abstractmethod
The decorator marks a member abstract for classes using ABCMeta.
Version: Python 3.14; repository image, production runtime not attested
Syntax
@property
@abstractmethod
def unit(self): ...The decorator marks a member abstract for classes using ABCMeta.
abc.abstractmethod
Place abstractmethod closest to def when combining it with property or classmethod. An abstract method can supply an implementation usable through super() in the override.
Base requires unit and Scale extends the base m to return mm.
from abc import ABC,abstractmethod
class Base(ABC):
@classmethod
@abstractmethod
def make(cls): return cls()
assert Base.__abstractmethods__=={'make'}
class Concrete(Base):
@classmethod
def make(cls): return super().make()
assert type(Concrete.make()) is Concrete
Examples
from abc import ABC, abstractmethod
class Base(ABC):
@property
@abstractmethod
def unit(self): return "m"
class Scale(Base):
@property
def unit(self): return super().unit + "m"
print(sorted(Base.__abstractmethods__), Scale().unit)
Result
['unit'] mm
Base requires unit and Scale extends the base m to return mm.