Repository navigation
fix: recognize @override on property getter with setter - #5098
Closed
Aayushyaash wants to merge 1 commit into
Closed
Aayushyaash wants to merge 1 commit into
Aayushyaash wants to merge 1 commit into
Conversation
When a property defines both a getter and a setter, the class field binds to the setter function, causing ClassField::is_override() to ignore @OverRide on the getter. This change checks both the top-level function and property_metadata so that @OverRide on either component is recognized while preserving bad-override checks, accompanied by regression tests.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D123282831. (Because this pull request was imported automatically, there will not be any future comments.) |
|
Diff from mypy_primer, showing the effect of this PR on open source code: ============================================================
SUMMARY
============================================================
Total: +0 new errors, -2 fixed errors
By preset: +0/-0 (default), +0/-2 (strict)
Projects with changes (2):
zulip: +0 -1
core: +0 -1
============================================================
FULL DIFF DETAILS
------------------------------------------------------------
zulip (https://github.com/zulip/zulip)
- ERROR zerver/lib/response.py:45:9-16: Class member `MutableJsonResponse.content` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
core (https://github.com/home-assistant/core)
- ERROR homeassistant/components/zha/config_flow.py:160:9-13: Class member `BaseZhaFlow.hass` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator] |
rchen152
approved these changes
Oct 6, 2026
rchen152
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Contributor
|
Thanks @Aayushyaash! |
Contributor
|
This pull request has been merged in c9e8429. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a subclass overrides a property that defines both a getter and a setter, Python's class evaluation binds the class attribute to the setter function.
Previously,
ClassField::is_override()only checked the top-level functionty.is_override(). When@overridewas placed on the getter, it was missed because the getter is stored insidety.property_metadata(), resulting in a false-positivemissing-override-decoratorerror.This PR updates
ClassField::is_override()to check if either the top-level function or any constituent function inproperty_metadata(getter or setter) has the@overridedecorator, while preserving bad-override checks when no parent attribute exists.Fixes #5058
Test Plan
Added regression tests in
pyrefly/lib/test/class_overrides.rsfor:@overrideand a setter@override@override@overrideon a property with no corresponding base class attribute, ensuringBadOverrideis still reportedValidation: