79707991

Date: 2025-07-20 12:45:01
Score: 0.5
Natty:
Report link

you're manually creating the class using the metaclass. And here's the catch:

__init_subclass__ only gets called when you define a class using the class keyword — not when you manually create it using a metaclass like Meta(...).

So yeah, that's why you're not seeing the print() output , Python just doesn't automatically call __init_subclass__ in this situation.

So what can you do?

If you still want __init_subclass__ to run when creating classes dynamically, you'll have to call it yourself inside your metaclass. Something like the below:
This way, you're mimicking what Python does under the hood when you use the class statement.

for base in bases:
    if hasattr(base, '__init_subclass__'):
        base.__init_subclass__(new_cls)

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Abdur Rahman