Skip to content

Conversation

@jackulau
Copy link
Contributor

Summary

Adds support for displaying inlay hints on variables created by tuple unpacking.

Before: Variables from tuple unpacking like x, y = (a, b) showed no inlay hints.

After: Each unpacked variable shows its individual type hint:

  • x: Literal[1]
  • y: Literal[1]

Changes

  • Handle Binding::UnpackedValue in inlay hints generation (inlay_hints.rs)
  • Add helper function get_unpacked_element_expr() to extract element expressions from tuple/list literals
  • For nested unpacking or function calls where element expressions can't be extracted, fall back to showing hints based on type information
  • Skip hints for literal values (e.g., x, y = (1, 2) shows no hints)
  • Respect existing annotations (no hints when variables are already annotated)

Test plan

Added 7 new test cases

  • test_tuple_unpacking_inlay_hint - Basic tuple unpacking: x, y = (a, b)
  • test_tuple_unpacking_from_function_call - Unpacking from function calls: x, y = f()
  • test_tuple_unpacking_no_hint_for_literals - No hints for literals: x, y = (1, 2)
  • test_tuple_unpacking_with_prior_annotation - Prior annotations respected
  • test_nested_tuple_unpacking - Nested unpacking: (a, b), c = f(), 3
  • test_starred_unpacking_from_function - Starred unpacking from function
  • test_starred_unpacking_from_literal - Starred unpacking from literal

@meta-cla meta-cla bot added the cla signed label Jan 14, 2026
@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
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This looks good to me, I'll try to get a second review + merge

@meta-codesync
Copy link

meta-codesync bot commented Jan 14, 2026

@stroxler has imported this pull request. If you are a Meta employee, you can view this in D90653949.

@stroxler stroxler self-assigned this Jan 14, 2026
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