Skip to content

fix: show setter type and accessors on property assignment hover - #5572

Open
Aayushyaash wants to merge 2 commits into
meta:mainfrom
Aayushyaash:fix-hover-property-setter-assignment
Open

Aayushyaash wants to merge 2 commits into
meta:mainfrom
Aayushyaash:fix-hover-property-setter-assignment

Conversation

@Aayushyaash

Copy link
Copy Markdown
Contributor

Summary

When hovering over a property or descriptor assignment target (e.g. a.x = 1), Pyrefly previously returned no hover information, even though hovering over property reads (a.x) worked correctly.

This happened because assignment checking returned None for property and descriptor setters to prevent getter types from leaking into assignment targets, leaving these targets without hover information.

This PR fixes the issue by:

  1. Separating flow-sensitive attribute narrowing from target type tracing in check_assign_to_attribute_and_infer_narrow, which now returns AttrAssignResult { narrowed, target_type }.
  2. Recording target_type via record_type_trace in solve.rs so hover displays the setter's parameter type, while keeping narrowed as None to prevent instance attributes from being incorrectly narrowed in subsequent read flows.
  3. Extracting setter value parameter types for bound and unbound property and descriptor setters using get_property_setter_value and get_descriptor_setter_value.
  4. Updating hover formatting in hover.rs to display the canonical attribute type for symmetric properties and both getter and setter types under Property Accessors for asymmetric properties and descriptors.

Fixes #5218

  • I am a human, and I fully understand the code I am submitting.

Test Plan

Added tests in pyrefly/lib/test/lsp/write_target_type.rs and pyrefly/lib/test/lsp/hover.rs covering:

  • Returning setter parameter types instead of None for property and descriptor assignments (p.p = "s", d.d = 1).
  • Displaying (attribute) x: int | None for symmetric property assignments.
  • Displaying the setter parameter type as the primary attribute type and both accessors under Property Accessors for asymmetric properties.
  • Preserving getter types on property reads without leaking setter types or RHS assignment literals.
  • Generic property assignments (Box[T].val = 2) and custom descriptor assignments (h.attr = [1, 2]).

Validation

cargo check
cargo test -p pyrefly test_property_and_descriptor_target
cargo test -p pyrefly hover_on_property_assignment_target
cargo test -p pyrefly write_target_type
python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema --no-extension

@meta-cla meta-cla Bot added the cla signed label Nov 7, 2026
@github-actions github-actions Bot added the size/l label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

✅ This PR meets all requirements from our pull request checklist.

Optional recommendations:

  • This PR is on the larger side. If parts of it could be merged on their own, consider splitting it into separate PRs for faster review. If you've already split it as far as is practical, no action is needed.

Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour.

@meta-codesync

meta-codesync Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D130432254. (Because this pull request was imported automatically, there will not be any future comments.)

@Aayushyaash
Aayushyaash marked this pull request as draft November 7, 2026 16:02
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@Aayushyaash
Aayushyaash marked this pull request as ready for review November 7, 2026 16:26
@github-actions
github-actions Bot requested a review from rchen152 November 8, 2026 09:06

This branch has not been deployed

No deployments
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.

Hover on property with setter during assignment shows nothing

2 participants