Metaclasses in Python
In Python, everything is an object, even the classes that create objects. You
used a class to instantiate an object instance, but classes themselves are
also instantiated behind the scenes. This mechanism is available to you as a
programmer through the concept of metaclasses.
Metaclasses allow you to hook
when classes are created, and this technique is what’s behind magical
frameworks like Django and SQLAlchemy where class definitions have side
effects that impact databases.
In this course you’ll learn about how:
- Everything really is an object, including classes themselves
- The
type()
function works - Classes instantiate objects and get instantiated themselves
- You can hook class instantiation with the metaclass argument
Metaclasses aren’t for the faint of heart, but they do