Repository navigation
fix: show setter type and accessors on property assignment hover - #5572
Open
Aayushyaash wants to merge 2 commits into
Open
Aayushyaash wants to merge 2 commits into
Aayushyaash wants to merge 2 commits into
Conversation
|
✅ This PR meets all requirements from our pull request checklist. Optional recommendations:
Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour. |
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
marked this pull request as draft
November 7, 2026 16:02
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This branch has not been deployed
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 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
Nonefor 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:
check_assign_to_attribute_and_infer_narrow, which now returnsAttrAssignResult { narrowed, target_type }.target_typeviarecord_type_traceinsolve.rsso hover displays the setter's parameter type, while keepingnarrowedasNoneto prevent instance attributes from being incorrectly narrowed in subsequent read flows.get_property_setter_valueandget_descriptor_setter_value.hover.rsto display the canonical attribute type for symmetric properties and both getter and setter types under Property Accessors for asymmetric properties and descriptors.Fixes #5218
Test Plan
Added tests in
pyrefly/lib/test/lsp/write_target_type.rsandpyrefly/lib/test/lsp/hover.rscovering:Nonefor property and descriptor assignments (p.p = "s",d.d = 1).(attribute) x: int | Nonefor symmetric property assignments.Box[T].val = 2) and custom descriptor assignments (h.attr = [1, 2]).Validation