fix Dataclass/Pydantic: go-to-def on named arguments in an __init__ call should go to specific fields #1231#2506
Open
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Open
fix Dataclass/Pydantic: go-to-def on named arguments in an __init__ call should go to specific fields #1231#2506asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
There was a problem hiding this comment.
Pull request overview
This PR fixes go-to-definition behavior for keyword arguments in class constructor calls. When using go-to-definition on a named argument in a class instantiation (e.g., Foo(x=1)), it now correctly navigates to the class field annotation (x: int) instead of the __init__ parameter. This aligns with the expected behavior for dataclasses and Pydantic models where fields are defined as class attributes.
Changes:
- Enhanced keyword argument definition resolution to prefer class field annotations over
__init__parameters - Added test coverage for class field keyword argument navigation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pyrefly/lib/state/lsp.rs | Implements new logic to resolve keyword argument definitions by checking class fields first, then falling back to __init__ parameters |
| pyrefly/lib/test/lsp/definition.rs | Adds test case verifying that go-to-definition on keyword arguments in class constructors navigates to class field annotations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Fixes #1231
Updated keyword-argument go-to-definition so class-constructor calls prefer class field annotations and fall back to
__init__parameters, which aligns with issue #1231.Test Plan
Added a class-field keyword-argument definition test