If you want to know what metaclasses are, go look on the web. Quoting from somewhere,
Most Python programmers rarely, if ever, have to think about metaclasses
Except me. Except me. I have to think about them all the time. And I’m not a Python programmer. What I want to know is the options, the form for coding, and when when they run. Heve you ever wanted/needed to override a metaclass? I have.
Sample Code
So,
Output,
Notes
Order is,
Metaclass: __prepare__
Metaclass: __new__
Class: __init_subclass__
Class: __new__
Class: __init__
And usage,
Metaclass __prepare__ is stated as having several uses. However, it’s class reference is only itself, the metaclass, so it can only tinker with the base dictionary and bases. See the PEP.
Metaclass __new__ is a bit more useful, as it is called with all the methods and properties to be attached, as well as the bases.
Class __init_subclass__, used as it is here, for sure has uses, but runs after Metaclass __new__, so you will not be getting in beforehand with this one.
Class __new__ runs after MetaClass __init__ code, so is hampered if you are already dealing with metaclasses.
Overall, you face what I call the ‘I’m most important’ problem. Ask any part of a democratic and collaborative venture, and they will tell you they are the most important part. For sure, if you are already dealing with code where people thought it would be cool to use metaclasses, your chances of anticipating that code using an override are limited. Best you can do is try modify afterwards.
Anyway, it will do for me, and if it helps you, good.
References
Metaclasses in Python 3000, new‐style declaration and __prepare__,