3 ms·
The most salient example I can think of is tracking all subclasses of a class. This is how django tracks `Model` subclasses to create a table for each model, fo
by tybug 5y ago
The most salient example I can think of is tracking all subclasses of a class. This is how django tracks `Model` subclasses to create a table for each model, for instance. I wrote a blog post on this topic: https://tybug.github.io/2021/11/06/tracking-all-subclasses-of-a-class.html https://tybug.github.io/2021/11/06/tracking-all-subclasses-o...
I've also used metaclasses in the past to apply a decorator to certain methods of all subclasses, without needing to specify that decorator in the subclass declaration itself.
- dbrueck 5y agoCame here to say this. This is my most common use of metaclasses, and __init_subclass__ looks to be a much cleaner solution.