Skip to content

[Types] Support inheritance for @qd.dataclass#717

Open
hughperkins wants to merge 3 commits into
mainfrom
hp/qd-dataclass-inheritance
Open

[Types] Support inheritance for @qd.dataclass#717
hughperkins wants to merge 3 commits into
mainfrom
hp/qd-dataclass-inheritance

Conversation

@hughperkins

Copy link
Copy Markdown
Collaborator

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

hughperkins and others added 2 commits June 2, 2026 11:39
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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread python/quadrants/lang/struct.py Outdated
Comment on lines +835 to +836
inherited_fields.update(parent_struct.members)
inherited_methods.update(parent_struct.methods)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant