[Types] Support inheritance for @qd.dataclass#717
Conversation
A @qd.dataclass returns a StructType instance rather than a class, so it could not previously be used as a base class. Add StructType.__mro_entries__ (PEP 560) so it can stand in as a base, and merge the parent's members and methods into the subclass in dataclass(). Subclasses inherit members and @qd.func methods, and may add to or override them. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8ea6d18010
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| inherited_fields.update(parent_struct.members) | ||
| inherited_methods.update(parent_struct.methods) |
There was a problem hiding this comment.
Preserve leftmost base precedence
When a dataclass subclasses multiple @qd.dataclass bases that define the same member or @qd.func name, these update() calls let the rightmost base overwrite the leftmost one. For class C(A, B), Python's normal MRO gives A precedence over B, so this makes the documented multiple-inheritance support compile kernels with the wrong inherited field type or method implementation for conflicting base names.
Useful? React with 👍 / 👎.
For multiple inheritance (class C(A, B)) where bases declare a conflicting member or @qd.func name, the leftmost base must win, matching Python's MRO. Visit bases left-to-right and never overwrite an already-seen name, so A wins over B while members keep their natural leftmost-base-first order. Addresses PR review feedback. Co-authored-by: Cursor <cursoragent@cursor.com>
A @qd.dataclass returns a StructType instance rather than a class, so it could not previously be used as a base class. Add StructType.mro_entries (PEP 560) so it can stand in as a base, and merge the parent's members and methods into the subclass in dataclass(). Subclasses inherit members and @qd.func methods, and may add to or override them.
Issue: #
Brief Summary
copilot:summary
Walkthrough
copilot:walkthrough