Learn Python metaclasses in one minute!

Antonis Christofides
Django Deployment
Published in
2 min readDec 11, 2020

Apologies for the off topic; this has nothing to do with Django deployment, and I promise it won’t happen often. I explained metaclasses to a friend and he thought I should publish it, and it’s fun, so here it goes.

The reason you are confused by metaclasses is that it’s a mistake Guido van Rossum made. To be precise, it’s one of the two big mistakes he made with respect to Python (the other one is the conditional expression, a if b else c). The mistake is in the naming. First, they’re not classes (they’re callables). In addition, they aren’t meta (they couldn’t be since they aren’t classes). It’s something like the English horn, which is neither English nor a horn (it’s a kind of French oboe). It’s like neural networks, which aren’t networks, and they aren’t neural either (a better name would be non-linear regression models).

Go read the official Python documentation on “metaclasses”, but whenever you see “metaclass”, either in code or in text, mentally replace it with “class creator”. That is all. You will have no difficulty.

The picture of the English horn is © 2010 Wikimedia user Hustvedt and licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.

This is a republication of an old article first published in my Django Deployment site.

--

--

Antonis Christofides
Django Deployment

I help scientists and engineers bring their models to the web