Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit966eff9

Browse files
authored
[3.12]gh-122026: Fix identification of mismatched parentheses inside f-strings (GH-122028) (#122062)
(cherry picked from commit2009e25)Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent0298da4 commit966eff9

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

‎Lib/test/test_fstring.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ def test_missing_expression(self):
921921
"f'{:2}'",
922922
"f'''{\t\f\r\n:a}'''",
923923
"f'{:'",
924+
"F'{[F'{:'}[F'{:'}]]]",
924925
],
925926
)
926927

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug that caused the tokenizer to not correctly identify mismatched
2+
parentheses inside f-strings in some situations. Patch by Pablo Galindo

‎Parser/tokenizer.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,6 +2607,9 @@ static int tok_get_normal_mode(struct tok_state *tok,
26072607

26082608
if (INSIDE_FSTRING(tok)) {
26092609
current_tok->curly_bracket_depth--;
2610+
if (current_tok->curly_bracket_depth<0) {
2611+
returnMAKE_TOKEN(syntaxerror(tok,"f-string: unmatched '%c'",c));
2612+
}
26102613
if (c=='}'&&current_tok->curly_bracket_depth==
26112614
current_tok->curly_bracket_expr_start_depth) {
26122615
current_tok->curly_bracket_expr_start_depth--;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp