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

Commitb13a3cd

Browse files
committed
[3.13]gh-130618: Fix parser error when using lambdas inside f-strings (GH-130638)
(cherry picked from commite06bebb)Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent676ceca commitb13a3cd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

‎Lib/test/test_grammar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,18 @@ async def foo():
20302030
withself.assertRaises(Done):
20312031
foo().send(None)
20322032

2033+
deftest_complex_lambda(self):
2034+
deftest1(foo,bar):
2035+
return""
2036+
2037+
deftest2():
2038+
returnf"{test1(
2039+
foo=lambda:'、、、、、、、、、、、、、、、、、',
2040+
bar=lambda:'abcdefghijklmnopqrstuvwxyz 123456789 123456789',
2041+
)}"
2042+
2043+
self.assertEqual(test2(),"")
2044+
20332045

20342046
if__name__=='__main__':
20352047
unittest.main()

‎Parser/lexer/lexer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,13 @@ _PyLexer_update_fstring_expr(struct tok_state *tok, char cur)
211211
break;
212212
case'}':
213213
case'!':
214-
case':':
215214
tok_mode->last_expr_end=strlen(tok->start);
216215
break;
216+
case':':
217+
if (tok_mode->last_expr_end==-1) {
218+
tok_mode->last_expr_end=strlen(tok->start);
219+
}
220+
break;
217221
default:
218222
Py_UNREACHABLE();
219223
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp