Disallow newlines in format specifiers of single quoted f- or t-strings (#18708)

This commit is contained in:
Micha Reiser 2025-06-18 14:56:15 +02:00 committed by GitHub
parent 23261a38a0
commit 1188ffccc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 521 additions and 513 deletions

View file

@ -169,15 +169,7 @@ Module(
InterpolatedStringFormatSpec {
range: 226..228,
node_index: AtomicNodeIndex(..),
elements: [
Literal(
InterpolatedStringLiteralElement {
range: 226..228,
node_index: AtomicNodeIndex(..),
value: "\\",
},
),
],
elements: [],
},
),
},
@ -385,11 +377,22 @@ Module(
6 | 'format spec'}
7 |
8 | f'middle {'string':\\
| ^ Syntax Error: f-string: unterminated string
| ^^ Syntax Error: f-string: newlines are not allowed in format specifiers when using single quotes
9 | 'format spec'}
|
|
6 | 'format spec'}
7 |
8 | f'middle {'string':\\
| ^ Syntax Error: f-string: expecting '}'
9 | 'format spec'}
10 |
11 | f'middle {'string':\\\
|
|
8 | f'middle {'string':\\
9 | 'format spec'}

View file

@ -384,7 +384,7 @@ Module(
3 | f"hello {x
4 | 2 + 2
5 | f"hello {x:
| ^ Syntax Error: f-string: unterminated string
| ^ Syntax Error: f-string: newlines are not allowed in format specifiers when using single quotes
6 | 3 + 3
7 | f"hello {x}
|