Introduction to Metaclasses in Python3:25pm - 3:55pm on Friday, October 2 in Online
In this talk, we’ll explore metaclasses in Python and learn how to leverage
them for having custom behavior across the codebase. We’ll explore the
type and how it comes into play in metaclasses. Lastly, we’ll
cover how metaclasses can be useful for Abstract Base Classes which comes
from the abc module in the standard library.
A class is a blueprint for an object. It describes how an instance of the class (ie an object) would behave. A metaclass is the class of a class. It defines how a class behaves. When you define a class in Python, its metaclass is called which when combined with init and new methods allows doing extra things like registering class with some registry or replace it entirely with something different.
The whole magic comes with type. It is a metaclass in Python, which itself is a class and it is of its own type. (yes, inception!).