Metaclasses Demystified
summary
Covers what metaclasses are and how they actually change class creation showing concrete code patterns: implements a singleton metaclass that caches instances, uses __new__ to raise TypeError and enforce forbidden methods for compile‑time checks, overrides prepare for enum‑style attribute storage, mutates the MRO to append fallback behavior, and defines class dunder methods on the metaclass (ABCMeta usage included). Ends with a real incident where a metaclass solved test resource injection but a simpler non‑metaclass design proved preferable.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 2:06What are metaclasses
- 3:06Whats a class
- 5:23Metaclass magic
- 6:09What do metaclasses do
- 9:07Singletons
- 12:22Controlling Class Methods
- 14:29Class Name Space
- 16:07Method Resolution Order
- 18:27Class Dunder Methods
- 20:42Object Base Class
- 25:06Question
related talks
30mThe Wizardry of Metaprogramming
01h 10mIt's Pythons All The Way Down: Python Types & Metaclasses Made Simple
57mThe Art of Subclassing
33mMetaprogramming in Python
26mEverything you need to know but were afraid to ask about Data Classes
47mA Deep-Dive Into Python Classes
36mPractical Python Design Patterns
24mJavaScript classes for the Python Programmer
