Skip to content

Fix Resolve TypedDict keys in go-to-definition - #4398

Open
aodihis wants to merge 2 commits into
facebook:mainfrom
aodihis:feature/4360
Open

Fix Resolve TypedDict keys in go-to-definition#4398
aodihis wants to merge 2 commits into
facebook:mainfrom
aodihis:feature/4360

Conversation

@aodihis

@aodihis aodihis commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #4360

Go-to-definition did not handle TypedDict subscript keys. In person["name"], "name" is a string literal, so no identifier is found and the request enters the None case. It then falls back to operator navigation and incorrectly resolves to dict.__getitem__.

This adds TypedDict handling before the operator fallback. It resolves keys using the inferred TypedDict fields and MRO, supporting class-based, inherited, and functional TypedDicts.

If the TypedDict does not contain the key, go-to-definition now returns no definition instead of falling back to __getitem__.

Test Plan

Added:

  • typed_dict_key_test for class-based, inherited, and functional TypedDicts.
  • typed_dict_missing_key_test to verify missing keys return no definition.

TypedDict string keys currently fall through to operator navigation and resolve to dict.__getitem__. Resolve literal keys against the inferred TypedDict class fields and MRO before that fallback, covering class-based, inherited, and functional declarations while preserving ordinary subscript behavior.
@meta-cla meta-cla Bot added the cla signed label Aug 1, 2026
@github-actions github-actions Bot added the size/m label Aug 1, 2026
@meta-codesync

meta-codesync Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@aodihis aodihis changed the title [pyrefly] Resolve TypedDict keys in go-to-definition Fix Resolve TypedDict keys in go-to-definition Aug 2, 2026
Distinguish declared TypedDict key access from ordinary subscripts before resolving the field. This lets missing fields return no definition instead of falling through to __getitem__, while keeping the field lookup itself optional and covering both class and functional declarations.
@github-actions github-actions Bot added size/l and removed size/m labels Aug 2, 2026
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

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

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.

Support go-to-definition for functional TypedDicts

2 participants