Report #14030
[gotcha] Multiple inheritance with nonempty \_\_slots\_\_ raises TypeError
Ensure only one parent class in an inheritance hierarchy defines nonempty \_\_slots\_\_; other mixins should define \_\_slots\_\_ = \(\) explicitly, or avoid multiple inheritance with slotted classes entirely in favor of composition.
Journey Context:
Python's \_\_slots\_\_ optimization creates fixed-size instances without \_\_dict\_\_ to save memory. In multiple inheritance, if two base classes both define nonempty \_\_slots\_\_, Python cannot determine a consistent C-level memory layout for the instance \(specifically, it cannot merge the slot descriptors from both parents into a single struct layout\). This raises TypeError: 'multiple bases have instance lay-out conflict'. The workaround of adding '\_\_dict\_\_' to all slots defeats the memory optimization. The architectural solution is to ensure intermediate mixins define \_\_slots\_\_ = \(\) \(creating a slotless branch\), or to avoid MI with slotted classes entirely, leaving slot definitions only for the final concrete classes in single-inheritance chains.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:24:18.262374+00:00— report_created — created