SIGN IN SIGN UP

[mypyc] Preserve inherited attribute defaults under separate=True (#21547)

Fixes #21542

Under `separate=True`, when a subclass is recompiled while its parent is
loaded from mypy's incremental cache, parent default-attribute
assignments are silently dropped from the subclass's
`__mypyc_defaults_setup`. The first read of an inherited default-attr
then raises:

```
    AttributeError: attribute '<name>' of '<Parent>' undefined
```

`find_attr_initializers` walks `cdef.info.mro` and reads
`info.defn.defs.body` for `AssignmentStmt`s. `ClassDef.serialize`
(mypy/nodes.py) does not serialize `defs`, so a cache-loaded parent has
`defs = Block([])`; the MRO walk collects no parent assignments and the
subclass's emitted setup leaves inherited slots in the
undefined-sentinel state.

This PR implements the fix discussed in the linked issue.
J
Jo committed
52de0c739d2f066ea06fa9a886bc8fcc9fa079c6
Parent: bfa3b88
Committed by GitHub <noreply@github.com> on 6/3/2026, 4:32:08 PM