On this page
abc.ABCMeta
Prev: abc.ABC | Up: abc | Next: abc.abstractclassmethod
Rel: abc.ABC, abc.abstractclassmethod, abc.abstractmethod, abc.abstractproperty
Ref: docs.python.org โ abc.ABCMeta
Tags: #public #python3 #stdlib #abc
Import
import abc
from abc import ABCMeta
Signature & Overview
abc.ABCMeta(name, bases, namespace, /, **kwargs)
Metaclass for defining Abstract Base Classes (ABCs).
Methods & Attributes
ABCMeta.mro(self, /)โ Return a type's method resolution order.ABCMeta.register(cls, subclass)โ Register a virtual subclass of an ABC.
Usage
from abc import ABCMeta, abstractmethod
class Greeter(metaclass=ABCMeta):
@abstractmethod
def greet(self) -> str: ...
class VirtualGreeter:
def greet(self) -> str: return "hi"
Greeter.register(VirtualGreeter)
assert isinstance(VirtualGreeter(), Greeter)
Gotchas
- Virtual subclasses via
.register()bypass abstractmethod checks: Useclass Foo(ABC):unless you need custom metaclass composition.
REPL Inspect
from abc import ABCMeta
help(ABCMeta)
Linked from
- tuts/python3/stdlib_module/abc
- tuts/python3/stdlib_module/abc/ABC
- tuts/python3/stdlib_module/abc/abstractclassmethod
- tuts/python3/stdlib_module/abc/abstractmethod
- tuts/python3/stdlib_module/abc/abstractproperty
- tuts/python3/stdlib_module/abc/abstractstaticmethod
- tuts/python3/stdlib_module/abc/get_cache_token
- tuts/python3/stdlib_module/abc/update_abstractmethods
Related notes
- tuts/python3/stdlib_module/abc/ABC Linked here; links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/abstractclassmethod Linked here; links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/abstractmethod Linked here; links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/abstractproperty Linked here; links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/abstractstaticmethod links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/get_cache_token links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc/update_abstractmethods links to this page; shared tags: #abc, #stdlib
- tuts/python3/stdlib_module/abc links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib