Skip to content

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
asukaminato0721:1231
Open

fix Dataclass/Pydantic: go-to-def on named arguments in an __init__ call should go to specific fields #1231#2506
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:1231

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Feb 23, 2026

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

@meta-cla meta-cla bot added the cla signed label Feb 23, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review February 23, 2026 20:05
Copilot AI review requested due to automatic review settings February 23, 2026 20:05
@github-actions
Copy link

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

Dataclass/Pydantic: go-to-def on named arguments in an __init__ call should go to specific fields

2 participants