Skip to content

fix: record attribute definition index for assignment and deletion targets - #5181

Closed
Aayushyaash wants to merge 2 commits into
pyrefly-org:mainfrom
Aayushyaash:fix-rename-attribute-assignment
Closed

Aayushyaash wants to merge 2 commits into
pyrefly-org:mainfrom
Aayushyaash:fix-rename-attribute-assignment

Conversation

@Aayushyaash

Copy link
Copy Markdown
Contributor

Summary

When triggering a rename (textDocument/rename) on a class attribute, attribute reads (r.attr) and assignments to self.attr are renamed properly, but assignments through an instance (r.attr = val) and attribute deletions (del r.attr) are skipped across files.

Previously, attribute reads recorded references in Index.externally_defined_attribute_references via record_attribute_definition_index in expr.rs, but attribute assignments and deletions in solve.rs omitted this step.

This PR adds record_attribute_definition_index calls for attribute assignments and deletions so these references are included in rename and reference resolution.

Fixes #5082

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

Test Plan

Added an LSP interaction test in pyrefly/lib/test/lsp/lsp_interaction/rename.rs verifying that renaming a class attribute across modules updates attribute assignments and deletions, along with the declaration and other references.

Validation:

cargo test test_rename_cross_file_attribute_assignment_and_deletion
cargo clippy -p pyrefly
python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema --no-extension

@meta-cla meta-cla Bot added the cla signed label Oct 9, 2026
@github-actions github-actions Bot added the size/m label Oct 9, 2026
@meta-codesync

meta-codesync Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

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

@kinto0 kinto0 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.

thanks for the PR! it seems like this fixes it. let me do some further testing (make sure test failed before trunk, count how many new attribute indexes we have)

@meta-codesync meta-codesync Bot closed this in 8dc10f9 Oct 13, 2026
@meta-codesync

meta-codesync Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 8dc10f9.

@meta-codesync meta-codesync Bot added the Merged label Oct 13, 2026
@Aayushyaash
Aayushyaash deleted the fix-rename-attribute-assignment branch October 14, 2026 10:14
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.

Rename of a class attribute skips assignments through another object (r.attr = value)

2 participants