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

Commitf609bdc

Browse files
committed
gh-130618: Fix parser error when using lambdas inside f-strings
1 parentd027787 commitf609bdc

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
@@ -1972,6 +1972,18 @@ async def foo():
19721972
withself.assertRaises(Done):
19731973
foo().send(None)
19741974

1975+
deftest_complex_lambda(self):
1976+
deftest1(foo,bar):
1977+
return""
1978+
1979+
deftest2():
1980+
returnf"{test1(
1981+
foo=lambda:'、、、、、、、、、、、、、、、、、',
1982+
bar=lambda:'abcdefghijklmnopqrstuvwxyz 123456789 123456789',
1983+
)}"
1984+
1985+
self.assertEqual(test2(),"")
1986+
19751987

19761988
if__name__=='__main__':
19771989
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