astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.76k stars 1.09k forks source link

[red-knot] `reveal_type` should display raw characters #14330

Open dhruvmanila opened 11 hours ago

dhruvmanila commented 11 hours ago

Looking at something like:

from typing import Literal, reveal_type

x: Literal["\n"] = "\n"

reveal_type(x)

We get:

red-knot: Revealed type is `Literal["
  "]` [revealed-type]
Pyright: Type of "e" is "Literal['\n']"
mypy: Revealed type is "Literal['\n']"

I think it would be useful to not render the characters and instead display it as raw instead similar to Pyright and mypy.

MichaReiser commented 10 hours ago

We could try using https://doc.rust-lang.org/std/primitive.str.html#method.escape_debug when displaying Literal