Skip to content

fix dunder slots definition #4344 - #5627

Open
asukaminato0721 wants to merge 16 commits into
pyrefly-org:mainfrom
asukaminato0721:4344-dunder-slots-definition
Open

asukaminato0721 wants to merge 16 commits into
pyrefly-org:mainfrom
asukaminato0721:4344-dunder-slots-definition

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes part of #4344

add support for slots definition and hover (folded from #5628).

This PR supports references from a slots entry to attribute uses. Reverse references from an attribute to slots entries are completed in #5629.

stack on #5625

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

Test Plan

add test

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

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

Optional recommendations:

  • This PR is very large, which makes it slow and difficult to review. We strongly recommend splitting it into smaller PRs that can be merged independently. If that isn't possible, please structure it as a series of small commits. 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 12, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@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 thorough tests (all assignment forms, nested/local classes, unrelated strings). Requesting changes for the same structural reason as the feedback on #5587/#5588: the slots entry is recognized by matching AST shapes in the LSP, instead of going through the semantic information the checker already has. Details inline. These comments cover only the __slots__ commits; the __all__ commits are reviewed on #5587, #5588, and #5625.

Also, mypy_primer shows the same +10/-17 home-assistant core diff as #5588, which looks like primer noise. Please rerun it.

Comment thread pyrefly/lib/state/lsp.rs Resolved
Comment thread pyrefly/lib/test/lsp/hover.rs Resolved
Comment thread pyrefly/lib/test/lsp/local_find_refs.rs Resolved
Comment thread pyrefly/lib/test/lsp/definition.rs Resolved
Use the existing definition lookup to read the exported symbol type. Keep string literal types for strings outside __all__.
Read the current checked module’s final export answer so buffers, stubs, and unopened dependencies supply the correct type.
Resolve __all__ entries only after identifier lookup fails. Cover go-to-type-definition and remove unrelated hover changes.
Resolve each entry to its definition before adding its string content range. Respect import aliases so references to independent names remain separate.
Preserve local alias identity and retain export occurrences in the normal reference index so unopened modules need no navigation queries.
Keep string content ranges from export extraction and resolve navigation and references through the checked binding. Preserve interface documentation without changing symbol identity.
Use string content ranges to preserve quotes and prefixes. Keep local source definitions during reference operations so rename updates both source files and their stubs. Validate the target before offering rename.
Read the owning class and literal slot name from the existing AST nodes. Use attribute definition lookup to navigate to the field declaration.
Resolve slot names against a generic instance of their owning class. This displays the field type while preserving its type parameters.
@asukaminato0721
asukaminato0721 force-pushed the 4344-dunder-slots-definition branch from d52e3df to cbb8633 Compare November 14, 2026 04:21
@github-actions github-actions Bot added size/xl and removed size/l labels Nov 14, 2026
@github-actions

Copy link
Copy Markdown

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

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.

2 participants