Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

abc.ABC

Inheriting from ABC supplies abstract base class machinery through ABCMeta.

Version: Python 3.14; repository image, production runtime not attested

Syntax

class Reader(ABC): ...

Inheriting from ABC supplies abstract base class machinery through ABCMeta.

abc.ABC

Instantiation is blocked only while abstract members remain unimplemented. register makes a virtual subclass for isinstance and issubclass without inserting the ABC into its method resolution order.

Reader() raises TypeError. Concrete Fixed returns 7 and satisfies isinstance.

from abc import ABC
class Tag(ABC): pass
class External: pass
assert type(Tag()) is Tag
Tag.register(External)
assert issubclass(External,Tag) and Tag not in External.__mro__

Examples

from abc import ABC, abstractmethod
class Reader(ABC):
    @abstractmethod
    def read(self): pass
class Fixed(Reader):
    def read(self): return 7
try:
    Reader()
except TypeError as exc:
    print(type(exc).__name__)
print(Fixed().read(), isinstance(Fixed(), Reader))

Result

TypeError
7 True

Reader() raises TypeError. Concrete Fixed returns 7 and satisfies isinstance.

Sources