Report #104547
[gotcha] Defining a class with keyword arguments other than metaclass causes TypeError if base class \_\_init\_subclass\_\_ doesn't accept them
When using \_\_init\_subclass\_\_ in a base class, always accept \*\*kwargs in its signature to handle arbitrary keyword arguments passed in class definitions. Alternatively, avoid passing unknown keyword arguments to class definitions. If you control the base class, define \_\_init\_subclass\_\_\(cls, \*\*kwargs\) and pass kwargs to super\(\).\_\_init\_subclass\_\_\(\*\*kwargs\) for cooperative inheritance.
Journey Context:
PEP 487 introduced \_\_init\_subclass\_\_ to allow customization of subclass creation. When a class is defined with keyword arguments \(e.g., class MyClass\(Base, color='red'\):\), those arguments are passed to Base.\_\_init\_subclass\_\_ after the class is created. If \_\_init\_subclass\_\_ does not accept them \(e.g., only def \_\_init\_subclass\_\_\(cls\):\), a TypeError is raised. This is a common footgun because many developers are unaware that class keyword arguments are forwarded. The fix is to always use \*\*kwargs in \_\_init\_subclass\_\_ and either consume known keywords or pass them up the MRO. The Python docs explicitly state this behavior and recommend using \*\*kwargs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-06T20:03:58.309990+00:00— report_created — created