Repository navigation
fix: show setter type and accessors on property assignment hover - #5572
Aayushyaash wants to merge 4 commits into
Conversation
|
✅ This PR meets all requirements from our pull request checklist. Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour. |
|
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.) |
This comment has been minimized.
This comment has been minimized.
rchen152
left a comment
There was a problem hiding this comment.
Thanks for the PR! I think the direction is good, but we can simplify how we get the getter and setter types.
69fc41a to
a7ee41a
Compare
|
Thanks for the review and feedback! I've made the changes based on your suggestions and rebased the PR on the latest Simplified the property and descriptor handling by reusing the existing type trace instead of resolving the setter type again. Consolidated setter value parameter extraction into a single helper that defaults to implicit |
rchen152
left a comment
There was a problem hiding this comment.
Thanks, this is looking better.
ede5a9e to
b0321ac
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Thanks for the review! I overlooked removing |
|
This pull request has been merged in 4ac3141. |
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