Skip to content

Comments

fix class_metadata and regression test#2379

Closed
oopscompiled wants to merge 1 commit intofacebook:mainfrom
oopscompiled:fix/add-check-mro-class
Closed

fix class_metadata and regression test#2379
oopscompiled wants to merge 1 commit intofacebook:mainfrom
oopscompiled:fix/add-check-mro-class

Conversation

@oopscompiled
Copy link
Contributor

Summary

This PR addresses issue #2371 by reporting inconsistent type args when the same direct base class appears with different type parameters across inheritance paths. It also adds a regression test

Fixes #2371

Test Plan

python3 test.py

Copilot AI review requested due to automatic review settings February 10, 2026 20:27
@meta-cla
Copy link

meta-cla bot commented Feb 10, 2026

Hi @oopscompiled!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes pyrefly’s handling of inconsistent generic type arguments when the same direct base class is reached through multiple inheritance paths with different type parameters (Issue #2371), and updates the existing regression test to assert the expected diagnostic.

Changes:

  • Add detection + error reporting for conflicting type arguments associated with a direct base class during MRO linearization.
  • Update the regression test to expect the new InvalidInheritance error (and remove the “known bug” marker).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pyrefly/lib/alt/types/class_metadata.rs Tracks seen ancestors’ instantiated ClassTypes and emits an InvalidInheritance error when a direct base class is encountered with inconsistent type arguments across inheritance paths.
pyrefly/lib/test/generic_basic.rs Converts the prior “bug-marked” test into an asserting regression test by adding an # E: expected error on the inconsistent base instantiation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@migeed-z
Copy link
Contributor

Thank you for the contribution!
Could you also sign the Contributor License Agreement? this makes it possible to merge pull requests.

@migeed-z migeed-z self-assigned this Feb 10, 2026
@meta-cla
Copy link

meta-cla bot commented Feb 10, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the cla signed label Feb 10, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 10, 2026

@migeed-z has imported this pull request. If you are a Meta employee, you can view this in D92869958.

@github-actions
Copy link

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core)
+ ERROR homeassistant/components/tesla_fleet/entity.py:180:7-36: Class `TeslaFleetWallConnectorEntity` has inconsistent type arguments for base class `CoordinatorEntity`: `CoordinatorEntity[TeslaFleetEnergySiteHistoryCoordinator | TeslaFleetEnergySiteInfoCoordinator | TeslaFleetEnergySiteLiveCoordinator | TeslaFleetVehicleDataCoordinator]` and `CoordinatorEntity[TeslaFleetEnergySiteLiveCoordinator]` [invalid-inheritance]
+ ::error file=homeassistant/components/tesla_fleet/entity.py,line=180,col=7,endLine=180,endColumn=36,title=Pyrefly invalid-inheritance::Class `TeslaFleetWallConnectorEntity` has inconsistent type arguments for base class `CoordinatorEntity`: `CoordinatorEntity[TeslaFleetEnergySiteHistoryCoordinator | TeslaFleetEnergySiteInfoCoordinator | TeslaFleetEnergySiteLiveCoordinator | TeslaFleetVehicleDataCoordinator]` and `CoordinatorEntity[TeslaFleetEnergySiteLiveCoordinator]`

mkdocs (https://github.com/mkdocs/mkdocs)
+ ERROR mkdocs/plugins.py:493:7-23: Class `PluginCollection` has inconsistent type arguments for base class `MutableMapping`: `MutableMapping[Unknown, Unknown]` and `MutableMapping[str, BasePlugin[Unknown]]` [invalid-inheritance]
+ ::error file=mkdocs/plugins.py,line=493,col=7,endLine=493,endColumn=23,title=Pyrefly invalid-inheritance::Class `PluginCollection` has inconsistent type arguments for base class `MutableMapping`: `MutableMapping[Unknown, Unknown]` and `MutableMapping[str, BasePlugin[Unknown]]`

Copy link
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync
Copy link

meta-codesync bot commented Feb 11, 2026

@migeed-z merged this pull request in f4ddc2c.

@oopscompiled oopscompiled deleted the fix/add-check-mro-class branch February 11, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing error for inconsistent TypeVar ordering in base classes

4 participants