Consistently wrap tokens in parser diagnostics in backticks instead of 'quotes' (#21163)

The parser currently uses single quotes to wrap tokens. This is
inconsistent with the rest of ruff/ty, which use backticks.

For example, see the inconsistent diagnostics produced in this simple
example: https://play.ty.dev/0a9d6eab-6599-4a1d-8e40-032091f7f50f

Consistently wrapping tokens in backticks produces uniform diagnostics.
Following the style decision of #723, in #2889 some quotes were already
switched into backticks.

This is also in line with Rust's guide on diagnostics
(https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure):

> When code or an identifier must appear in a message or label, it
should be surrounded with backticks
This commit is contained in:
Luca Chiodini 2025-10-31 16:59:11 +01:00 committed by GitHub
parent bb40c34361
commit 69b4c29924
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
103 changed files with 359 additions and 359 deletions

View file

@ -1,20 +1,20 @@
# Comprehensions with invalid syntax
```py
# Missing 'in' keyword.
# Missing `in` keyword.
# It's reasonably clear here what they *meant* to write,
# so we'll still infer the correct type:
# error: [invalid-syntax] "Expected 'in', found name"
# error: [invalid-syntax] "Expected `in`, found name"
# revealed: int
[reveal_type(a) for a range(3)]
# Missing iteration variable
# error: [invalid-syntax] "Expected an identifier, but found a keyword 'in' that cannot be used here"
# error: [invalid-syntax] "Expected 'in', found name"
# error: [invalid-syntax] "Expected an identifier, but found a keyword `in` that cannot be used here"
# error: [invalid-syntax] "Expected `in`, found name"
# error: [unresolved-reference]
# revealed: Unknown
[reveal_type(b) for in range(3)]
@ -27,9 +27,9 @@
[reveal_type(c) for c in]
# Missing 'in' keyword and missing iterable
# Missing `in` keyword and missing iterable
# error: [invalid-syntax] "Expected 'in', found ']'"
# error: [invalid-syntax] "Expected `in`, found `]`"
# revealed: Unknown
[reveal_type(d) for d]
```

View file

@ -14,7 +14,7 @@ TODO: This is correctly flagged as an error, but we could clean up the diagnosti
```py
# TODO: No second diagnostic
# error: [invalid-syntax] "Expected ',', found '.'"
# error: [invalid-syntax] "Expected `,`, found `.`"
# error: [unresolved-import] "Module `a` has no member `c`"
from a import b.c