3 ms·
The one python pattern I used to use metaclasses for (registry types that keep an index of all their subclasses, very useful for DSL type tasks) is easier with
by bgribble 3y ago
The one python pattern I used to use metaclasses for (registry types that keep an index of all their subclasses, very useful for DSL type tasks) is easier with __init_subclass__ and is somewhat more readable. So I haven't used metaclass in a minute.
The worst thing about metaclass is that 95% of python programmers look at it and just go "whuzzat?" and require a seminar to catch a clue. It's actively hostile to whoever maintains the code after you.
- kstrauser 3y agoI'm with you completely about __init_subclass__. It covers almost all the uses where I'd otherwise use metaclasses. Junior engineers so that and say "oh, clever!", rather than running off screaming into the night.
- strbean 3y agoI too love attributes that can only be known at runtime and are therefore fundamentally un-type-hintable.
- nhumrich 3y agoAgree, but init_subclass is new to python 3. It almost feels like OPs advice is based on old python and not modern python.