mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-20 18:40:28 +00:00
Avoid curly brace escape in f-string format spec (#7780)
## Summary This PR fixes a bug in the lexer for f-string format spec where it would consider the `{{` (double curly braces) as an escape pattern. This is not the case as evident by the [PEP](https://peps.python.org/pep-0701/#how-to-produce-these-new-tokens) as well but I missed the part: > [..] > * **If in “format specifier mode” (see step 3), an opening brace ({) or a closing brace (}).** > * If not in “format specifier mode” (see step 3), an opening brace ({) or a closing brace (}) that is not immediately followed by another opening/closing brace. ## Test Plan Add a test case to verify the fix and update the snapshot. fixes: #7778
This commit is contained in:
parent
c040fac12f
commit
69b8136463
2 changed files with 69 additions and 4 deletions
|
@ -191,11 +191,76 @@ expression: lex_source(source)
|
|||
43..44,
|
||||
),
|
||||
(
|
||||
FStringEnd,
|
||||
FStringMiddle {
|
||||
value: " ",
|
||||
is_raw: false,
|
||||
},
|
||||
44..45,
|
||||
),
|
||||
(
|
||||
Lbrace,
|
||||
45..46,
|
||||
),
|
||||
(
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
46..47,
|
||||
),
|
||||
(
|
||||
Colon,
|
||||
47..48,
|
||||
),
|
||||
(
|
||||
Lbrace,
|
||||
48..49,
|
||||
),
|
||||
(
|
||||
Lbrace,
|
||||
49..50,
|
||||
),
|
||||
(
|
||||
Int {
|
||||
value: 1,
|
||||
},
|
||||
50..51,
|
||||
),
|
||||
(
|
||||
Rbrace,
|
||||
51..52,
|
||||
),
|
||||
(
|
||||
Dot,
|
||||
52..53,
|
||||
),
|
||||
(
|
||||
Name {
|
||||
name: "pop",
|
||||
},
|
||||
53..56,
|
||||
),
|
||||
(
|
||||
Lpar,
|
||||
56..57,
|
||||
),
|
||||
(
|
||||
Rpar,
|
||||
57..58,
|
||||
),
|
||||
(
|
||||
Rbrace,
|
||||
58..59,
|
||||
),
|
||||
(
|
||||
Rbrace,
|
||||
59..60,
|
||||
),
|
||||
(
|
||||
FStringEnd,
|
||||
60..61,
|
||||
),
|
||||
(
|
||||
Newline,
|
||||
45..45,
|
||||
61..61,
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue