← All notes

Python abc defines abstract base classes that cannot be instantiated until abstract methods are overridden

Answer: Create an abstract base class by deriving from the helper class ABC, and use the @abstractmethod decorator on abstract methods. A class with a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods are overridden. register(subclass) registers a virtual subclass of the ABC.

Example

from abc import ABC, abstractmethod

class Store(ABC):
    @abstractmethod
    def get(self, key): ...

class MemStore(Store):
    def get(self, key):
        return None

MemStore()   # ok
Store()      # TypeError
Store.register(dict)   # dict is now a virtual subclass

Facts

Origin

PEP 3119 was a proposal to add Abstract Base Class (ABC) support to Python 3000, including ABCs for containers and iterators.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs (library), abc — Abstract Base Classes; Python PEPs, PEP 3119 – Introducing Abstract Base Classes. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Public-Domain (https://peps.python.org/pep-0001/). PEP text is placed in the public domain (some also CC0-1.0). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs (library), abc — Abstract Base Classes; Python PEPs, PEP 3119 – Introducing Abstract Base Classes. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Public-Domain (https://peps.python.org/pep-0001/). PEP text is placed in the public domain (some also CC0-1.0).

Cite this

Permanent ID: iil:note:ebkb7t5b

iinventedlight. 2026. "Python abc defines abstract base classes that cannot be instantiated until abstract methods are overridden." iinventedlight Library, iil:note:ebkb7t5b, version of 2026-11-18. https://iinventedlight.com/library/notes/python-abc/. License: CC-BY-4.0.

@misc{iil_note_ebkb7t5b,
  author = {{iinventedlight}},
  title = {{Python abc defines abstract base classes that cannot be instantiated until abstract methods are overridden}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/python-abc/},
  note = {Permanent ID iil:note:ebkb7t5b. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-abc.md.