Skip to content

Goto definition, declaration, find references for typed dict and named tuple initializers#24897

Merged
MichaReiser merged 6 commits intomainfrom
goto-dc-td-nt-kw-args
Apr 28, 2026
Merged

Goto definition, declaration, find references for typed dict and named tuple initializers#24897
MichaReiser merged 6 commits intomainfrom
goto-dc-td-nt-kw-args

Conversation

@MichaReiser
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser commented Apr 28, 2026

Summary

Fixes goto definition, find references, rename, etc for synthesized methods and constructor calls.

Each Parameter now stores its definition, which the LSP can use. This allows synthesized functions and methods to set the parameter's definition to e.g. a TypedDict field.

The downside of this approach is that Parameter grows in size, as shown in the memory usage report. I consider the increase acceptable, given that it's ~0.10%.

I also decided to use parameter.definition for all parameters, not just synthesized methods. This simplifies our implementation and is free, because the memory increase is not from how many instances store a Definition, but that we need the Parameter.definition field in the first place.

Fixes astral-sh/ty#1881
Fixes astral-sh/ty#3207
Fixes astral-sh/ty#3348
Fixes astral-sh/ty#3349

Test

Added integration tests

@MichaReiser MichaReiser added server Related to the LSP server ty Multi-file analysis & type inference labels Apr 28, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 28, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 88.70%. The percentage of expected errors that received a diagnostic held steady at 84.63%. The number of fully passing files held steady at 84/134.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 28, 2026

Memory usage report

Summary

Project Old New Diff Outcome
prefect 703.41MB 704.16MB +0.11% (763.00kB)
sphinx 259.59MB 259.92MB +0.13% (343.02kB)
trio 116.80MB 116.95MB +0.13% (151.48kB)
flake8 47.72MB 47.76MB +0.09% (42.96kB)

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
FunctionType<'db>::signature_ 4.13MB 4.32MB +4.60% (194.42kB)
FunctionType<'db>::last_definition_raw_signature_ 3.47MB 3.64MB +4.80% (170.76kB)
FunctionType 8.98MB 9.14MB +1.81% (166.23kB)
CallableType 2.22MB 2.38MB +6.88% (156.59kB)
FunctionType<'db>::last_definition_signature_ 829.13kB 864.71kB +4.29% (35.58kB)
Type<'db>::apply_specialization_ 3.72MB 3.73MB +0.26% (10.03kB)
Type<'db>::apply_specialization_::interned_arguments 2.98MB 2.99MB +0.29% (8.75kB)
Specialization 2.12MB 2.13MB +0.32% (6.89kB)
is_redundant_with_impl 2.00MB 2.00MB +0.29% (5.91kB)
TupleType 733.14kB 737.62kB +0.61% (4.48kB)
is_redundant_with_impl::interned_arguments 2.12MB 2.12MB +0.14% (3.09kB)
GenericAlias 909.91kB 910.12kB +0.02% (216.00B)
infer_definition_types 89.52MB 89.52MB +0.00% (36.00B)
NamedTupleSpec 192.00B 208.00B +8.33% (16.00B)
infer_expression_types_impl 63.22MB 63.22MB +0.00% (12.00B)

sphinx

Name Old New Diff Outcome
FunctionType<'db>::signature_ 2.27MB 2.39MB +5.04% (117.23kB)
FunctionType<'db>::last_definition_raw_signature_ 2.04MB 2.14MB +4.76% (99.46kB)
FunctionType 3.11MB 3.18MB +2.20% (70.01kB)
CallableType 1.12MB 1.16MB +4.12% (47.09kB)
FunctionType<'db>::last_definition_signature_ 221.45kB 230.60kB +4.13% (9.15kB)
NamedTupleSpec 1016.00B 1.08kB +8.66% (88.00B)

trio

Name Old New Diff Outcome
FunctionType<'db>::signature_ 1.06MB 1.12MB +4.80% (52.30kB)
FunctionType 1.49MB 1.53MB +2.67% (40.62kB)
CallableType 579.61kB 607.77kB +4.86% (28.16kB)
FunctionType<'db>::last_definition_raw_signature_ 601.46kB 621.83kB +3.39% (20.37kB)
FunctionType<'db>::last_definition_signature_ 241.89kB 251.27kB +3.88% (9.38kB)
Type<'db>::apply_specialization_ 707.92kB 708.10kB +0.03% (184.00B)
Type<'db>::apply_specialization_::interned_arguments 625.78kB 625.94kB +0.02% (160.00B)
Specialization 456.70kB 456.83kB +0.03% (128.00B)
is_redundant_with_impl::interned_arguments 289.09kB 289.18kB +0.03% (88.00B)
is_redundant_with_impl 247.89kB 247.96kB +0.03% (72.00B)
UnionType<'db>::from_two_elements_ 41.64kB 41.66kB +0.06% (24.00B)
infer_definition_types 7.65MB 7.65MB +0.00% (12.00B)

flake8

Name Old New Diff Outcome
FunctionType<'db>::signature_ 360.42kB 378.48kB +5.01% (18.05kB)
FunctionType 437.97kB 449.97kB +2.74% (12.00kB)
CallableType 168.68kB 175.48kB +4.03% (6.80kB)
FunctionType<'db>::last_definition_raw_signature_ 80.73kB 84.47kB +4.64% (3.74kB)
FunctionType<'db>::last_definition_signature_ 59.28kB 61.64kB +3.98% (2.36kB)

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 28, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@MichaReiser MichaReiser force-pushed the goto-dc-td-nt-kw-args branch from 933b26f to 0f0e51b Compare April 28, 2026 10:33
Comment thread crates/ty_ide/src/goto_declaration.rs Outdated
|
7 | g: str
8 |
9 | def __init__(self, f: int) -> None: ...
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This matches pylance's behavior

Copy link
Copy Markdown
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

Very nice (and agree that this is a good tradeoff).

@MichaReiser MichaReiser force-pushed the goto-dc-td-nt-kw-args branch from 728d186 to 6cb41ac Compare April 28, 2026 15:36
@MichaReiser MichaReiser enabled auto-merge (squash) April 28, 2026 15:44
@MichaReiser MichaReiser merged commit dfba807 into main Apr 28, 2026
55 checks passed
@MichaReiser MichaReiser deleted the goto-dc-td-nt-kw-args branch April 28, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

3 participants