ruff
a7b52a15 - [ty] Preserve distinct string literal displays without deprecated ICU data (#29206)

Commit
6 days ago
[ty] Preserve distinct string literal displays without deprecated ICU data (#29206) Canonical equivalence can make distinct string values look the same. ty escapes their displays to distinguish them, but the current approach relies on ICU4X's deprecated `NfcInert` property, which [ICU4X plans to remove](https://github.com/unicode-org/icu4x/issues/7892), and can escape characters that do not need escaping. Replace inertness checks with NFC checks on runs of unescaped text. When adding a character would make a run non-NFC, escape that character and continue checking after it. The resulting string literal is in NFC and evaluates to the original value, so canonically equivalent values remain distinguishable. For example, `\u212b` (the Angstrom sign) is canonically equivalent to `Å`. ty now keeps the unrelated `é` visible while still distinguishing the two values: ```py reveal_type("éÅ") # main: Literal["éÅ"] # this PR: Literal["éÅ"] reveal_type("é\u212b") # main: Literal["\xe9\u212b"] # this PR: Literal["é\u212b"] ``` The change also uses Unicode grapheme-break properties to keep characters visually separate from the quotes and escape sequences around them. It escapes the braille blank because it can look like an ordinary space.
Author
Parents
Loading