Skip to content

[ty] Qualify inlay hint edit symbol when possibly referencing another variable#23265

Merged
BurntSushi merged 2 commits intoastral-sh:mainfrom
MatthewMckee4:inlay-hint-in-scope
Feb 13, 2026
Merged

[ty] Qualify inlay hint edit symbol when possibly referencing another variable#23265
BurntSushi merged 2 commits intoastral-sh:mainfrom
MatthewMckee4:inlay-hint-in-scope

Conversation

@MatthewMckee4
Copy link
Contributor

Summary

Resolves astral-sh/ty#2802

Previously we just checked if a symbol with the same name existed in the current scope.
But this is wrong as we can see in the issue, we should check if the symbol is the same as the one we want to import, if it is, then we don't need to import anything, if it is not the same symbol, we need to qualify the name so we directly reference the symbol for the other module.

Screen.Recording.2026-02-13.at.11.30.34.mov

Test Plan

Added a new test mirroring the example in the issue

@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Feb 13, 2026
@MatthewMckee4 MatthewMckee4 changed the title Qualify inlay hint symbol if there is already an in scope variable with the same name [ty] Qualify inlay hint edit symbol when possibly referencing another variable Feb 13, 2026
@BurntSushi BurntSushi self-assigned this Feb 13, 2026
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

I buy it! Thanks for the very quick fix!!!

@BurntSushi BurntSushi merged commit 8278f75 into astral-sh:main Feb 13, 2026
48 checks passed
@MatthewMckee4 MatthewMckee4 deleted the inlay-hint-in-scope branch February 13, 2026 22:09
carljm added a commit that referenced this pull request Feb 14, 2026
* main: (209 commits)
  [ty] Defer base inference for functional `type(...)` classes (#22792)
  flake8-executable: allow global flags in uv shebangs (EXE003) (#22582)
  [ty] Add `replace-imports-with-any` option (#23122)
  Update html comments in mdtests (#23269)
  Apply ruff formatting to mdtests (#22935)
  [ty] Exclude test-related symbols from non-first-party packages in auto-import completions
  [ty] Refactor `CursorTest` helper to support site-packages
  [ty] Qualify inlay hint edit symbol when possibly referencing another variable (#23265)
  [ty] Avoid `UnionBuilder` overhead when creating a new union from the filtered elements of an existing union (#22352)
  [ty] Refactor TypedDict key assignment validation (#23262)
  [ty] Improve Python environment path documentation (#23256)
  [ty] loop control flow analysis using loop header definitions
  Prepare for 0.15.1 (#23253)
  Remove docker-run-action (#23254)
  [ty] Allow discovering dependencies in system Python environments (#22994)
  Ensure pending suppression diagnostics are reported (#23242)
  [`isort`] support for configurable import section heading comments (#23151)
  [ty] Fix method calls on subclasses of `Any` (#23248)
  [ty] Fix bound method access on `None` (#23246)
  Make range suppression test snapshot actually useful (#23251)
  ...
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

Development

Successfully merging this pull request may close these issues.

Inlay hint inserting does not avoid name collisions

3 participants