Skip to content

Report invalid property signatures with extra required parameters - #4934

Closed
dedsec-terminal wants to merge 2 commits into
facebook:mainfrom
dedsec-terminal:fix/property-signature
Closed

dedsec-terminal wants to merge 2 commits into
facebook:mainfrom
dedsec-terminal:fix/property-signature

Conversation

@dedsec-terminal

@dedsec-terminal dedsec-terminal commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI lite review requested due to automatic review settings September 14, 2026 22:48
@meta-cla meta-cla Bot added the cla signed label Sep 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@meta-codesync

meta-codesync Bot commented Sep 14, 2026

Copy link
Copy Markdown
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 stroxler left a comment

Copy link
Copy Markdown
Contributor

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.

@github-actions

Copy link
Copy Markdown

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]

…ature

A custom decorator between @Property and the def (e.g. homeassistant

Spotify's @ensure_item turning (self, item) into (self)) makes the raw

def's extra required parameter valid. Only validate when no

non-special decorators remain; @override/@Final are already filtered.
@meta-codesync

meta-codesync Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 881210b.

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.

no error on invalid usage of @property

3 participants