Report invalid property signatures with extra required parameters - #4934
Closed
dedsec-terminal wants to merge 2 commits into
Closed
dedsec-terminal wants to merge 2 commits into
dedsec-terminal wants to merge 2 commits into
Conversation
The property decorator path attaches metadata without checking the decorated function against the fget/fset/fdel shapes declared on property in typeshed, so a getter like def value(self, huh: str) passed silently. Validate required parameters when the decorator is applied: one for getters and deleters, two for setters. Parameters with defaults stay allowed since they remain callable.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D120055424. (Because this pull request was imported automatically, there will not be any future comments.) |
stroxler
approved these changes
Sep 15, 2026
stroxler
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
Diff from mypy_primer, showing the effect of this PR on open source code: ============================================================
SUMMARY
============================================================
Total: +8 new errors, -0 fixed errors
By preset: +8/-0 (default), +8/-0 (strict)
Projects with changes (1):
core: +8 -0
============================================================
FULL DIFF DETAILS
------------------------------------------------------------
core (https://github.com/home-assistant/core)
+ ERROR homeassistant/components/spotify/media_player.py:168:32-42: Property getter cannot take extra required parameter `item` [bad-function-definition]
+ ERROR homeassistant/components/spotify/media_player.py:175:34-44: Property getter cannot take extra required parameter `item` [bad-function-definition]
+ ERROR homeassistant/components/spotify/media_player.py:182:30-40: Property getter cannot take extra required parameter `item` [bad-function-definition]
+ ERROR homeassistant/components/spotify/media_player.py:205:31-41: Property getter cannot take extra required parameter `item` [bad-function-definition]
+ ERROR homeassistant/components/spotify/media_player.py:224:27-37: Property getter cannot take extra required parameter `item` [bad-function-definition]
+ ERROR homeassistant/components/spotify/media_player.py:231:28-38: Property getter cannot take extra required parameter `item` [bad-function-definition]
+ ERROR homeassistant/components/spotify/media_player.py:245:32-42: Property getter cannot take extra required parameter `item` [bad-function-definition]
+ ERROR homeassistant/components/spotify/media_player.py:257:27-37: Property getter cannot take extra required parameter `item` [bad-function-definition] |
Contributor
|
This pull request has been merged in 881210b. |
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
The property decorator path attaches metadata without checking the decorated function against the fget/fset/fdel shapes declared on property in typeshed, so a getter like def value(self, huh: str) passed silently.
Validated required parameters when the decorator is applied: one for getters and deleters (self), two for setters (self, value). Extra required positional or keyword-only parameters now report an error. Parameters with defaults stay allowed since they remain callable, and static/class methods plus top-level functions are untouched.
Fixes #4918
Test Plan
4 new cases in pyrefly/lib/test/descriptors.rs (getter, setter, deleter errors, defaulted-extra clean). Ran descriptors (67 passed), decorators (62 passed), property filter (46 passed, 1 pydantic case needs PYDANTIC_TEST_PATH env), cached_property (3 passed). cargo fmt, check and clippy clean with no new warnings.