What is the purpose of the __init_subclass__ hook in Python?

Python Developer Medium

Python Developer — Medium

What is the purpose of the __init_subclass__ hook in Python?

Key points

  • __init_subclass__ enables customization without metaclasses
  • Helps in defining shared behavior for subclasses
  • Not related to initializing class-level attributes or preventing subclassing
  • Does not automatically call super().__init__() in subclasses

Ready to go further?

Related questions