fix class_metadata and regression test#2379
fix class_metadata and regression test#2379oopscompiled wants to merge 1 commit intofacebook:mainfrom
Conversation
|
Hi @oopscompiled! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
There was a problem hiding this comment.
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
InvalidInheritanceerror (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.
|
Thank you for the contribution! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
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]]`
|
stroxler
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
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