Hacker News new | ask | show | jobs
by kkirsche 1373 days ago
Thanks for sharing! Instead of using meta classes for subclass registration though, please just use __subclass_init__ instead. It’ll often be simpler unless you have a complex use case.

https://docs.python.org/3/reference/datamodel.html#object.__...

1 comments

Yes, also for anything else than subclass registration, there are things like the descriptor protocol or class decorators that are likely to be easier to use, debug and understand.

And metaclasses can be any callable, not just class. It's usually better to use a simple function.