Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Show LiteralString when hovering the inline of a literal string#25373

Merged
MichaReiser merged 2 commits into
mainfrom
micha/inlay-literal-string-hover
May 26, 2026
Merged

[ty] Show LiteralString when hovering the inline of a literal string#25373
MichaReiser merged 2 commits into
mainfrom
micha/inlay-literal-string-hover

Conversation

@MichaReiser

@MichaReiser MichaReiser commented May 24, 2026

Copy link
Copy Markdown
Member

Summary

Today, ty showed the hover for str when hovering the inlay of a LiteralString type:

from typing import LiteralString
def my_func(x: LiteralString):
    y[: LiteralString] = x
my_func(x="hello")

Hovering the inlay of y ([: LiteralString] is the inlay) showed the hover of str.

We argued in #21548 that str is generally the more useful type in this position. I sort of agree, but I think it's more important that the inlay and the hover show the same type. I also think that it's important that the hover is consistent with when we "bake" the inlay, e.g. hovering LiteralString now also shows LiteralString and not str

from typing import LiteralString
def my_func(x: LiteralString):
    y: LiteralString = x
my_func(x="hello")

Closes astral-sh/ty#2860

Test Plan

Updated test

@MichaReiser MichaReiser added the bug Something isn't working label May 24, 2026
@MichaReiser MichaReiser requested a review from carljm as a code owner May 24, 2026 15:47
@MichaReiser MichaReiser added server Related to the LSP server ty Multi-file analysis & type inference labels May 24, 2026
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila May 24, 2026 15:47
@astral-sh-bot

astral-sh-bot Bot commented May 24, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

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

@astral-sh-bot

astral-sh-bot Bot commented May 24, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 24, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

string.display_with(self.db, self.settings.clone()),
)
}
// an alternative would be to use `Type::SpecialForm(SpecialFormType::LiteralString)` here,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd lean towards updating the comment to explain why we show the docs for LiteralString instead of str here (your reasoning in the PR description is strong) rather than just deleting it

@MichaReiser MichaReiser enabled auto-merge (squash) May 26, 2026 07:32
@MichaReiser MichaReiser merged commit 6a3bc5b into main May 26, 2026
58 checks passed
@MichaReiser MichaReiser deleted the micha/inlay-literal-string-hover branch May 26, 2026 07:34
anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request May 28, 2026
astral-sh#25373)

## Summary

Today, ty showed the hover for `str` when hovering the inlay of a
`LiteralString` type:

```py
from typing import LiteralString
def my_func(x: LiteralString):
    y[: LiteralString] = x
my_func(x="hello")
```

Hovering the inlay of `y` (`[: LiteralString]` is the inlay) showed the
hover of `str`.

We argued in astral-sh#21548 that `str` is
generally the more useful type in this position. I sort of agree, but I
think it's more important that the inlay and the hover show the same
type. I also think that it's important that the hover is consistent with
when we "bake" the inlay, e.g. hovering `LiteralString` now also shows
`LiteralString` and not `str`

```py
from typing import LiteralString
def my_func(x: LiteralString):
    y: LiteralString = x
my_func(x="hello")
```

Closes astral-sh/ty#2860

## Test Plan

Updated test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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 on infered type with large string has incorrect details on LiteralString

3 participants