Skip to content

Clarify multiple-inheritance op merge in TorchAOBaseTensor docstring - #4955

Open
PlatformLC wants to merge 1 commit into
pytorch:mainfrom
PlatformLC:clarify-mro-docstring
Open

PlatformLC wants to merge 1 commit into
pytorch:mainfrom
PlatformLC:clarify-mro-docstring

Conversation

@PlatformLC

Copy link
Copy Markdown

Summary

Clarify a self-contradictory sentence in the TorchAOBaseTensor docstring about
op inheritance under multiple inheritance. Docstring-only; no code or behavior change.

Problem

Current text:

For multiple inheritance (e.g., class C(B, A)), ops are inherited from all parents
following Python's MRO (Method Resolution Order), with later bases taking priority.

The two clauses contradict each other: standard Python MRO gives the earlier
(leftmost) base priority, yet the sentence says the later base wins.

What the code actually does

__init_subclass__ walks cls.__bases__ in declaration order and merges each
parent's op table with dict.update
(see torchao/utils.py, the __init_subclass__ loop). A later-listed base
overwrites an earlier one on conflicts, so the later base does take priority —
but this is a flat overwrite merge, not standard MRO resolution. The original
sentence jumped from the MRO premise straight to the conclusion, skipping the
overwrite step that bridges them.

Change

Reword to state the mechanism directly, keeping MRO as the visit-order premise and
removing the contradiction:

For multiple inheritance (e.g., class C(B, A)), ops are inherited from all parents.
Each parent's table is merged in Python's MRO (Method Resolution Order), visiting B
then A; since each merge overwrites the previous, the later-listed base (A)
takes priority when both define the same op.

Notes

  • torchao/utils.py only; no functional change, no test impact.

@pytorch-bot

pytorch-bot Bot commented Sep 28, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4955

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 28, 2026

This branch has not been deployed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant