mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
[3.12] gh-130618: Fix parser error when using lambdas inside f-strings (GH-130638) (#130644)
(cherry picked from commit e06bebb87e
)
This commit is contained in:
parent
99e18abe6f
commit
0860d9c72f
3 changed files with 19 additions and 1 deletions
|
@ -2030,6 +2030,18 @@ class GrammarTests(unittest.TestCase):
|
||||||
with self.assertRaises(Done):
|
with self.assertRaises(Done):
|
||||||
foo().send(None)
|
foo().send(None)
|
||||||
|
|
||||||
|
def test_complex_lambda(self):
|
||||||
|
def test1(foo, bar):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def test2():
|
||||||
|
return f"{test1(
|
||||||
|
foo=lambda: '、、、、、、、、、、、、、、、、、',
|
||||||
|
bar=lambda: 'abcdefghijklmnopqrstuvwxyz 123456789 123456789',
|
||||||
|
)}"
|
||||||
|
|
||||||
|
self.assertEqual(test2(), "")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix a bug that was causing ``UnicodeDecodeError`` or ``SystemError`` to be
|
||||||
|
raised when using f-strings with ``lambda`` expressions with non-ASCII
|
||||||
|
characters. Patch by Pablo Galindo
|
|
@ -479,8 +479,11 @@ static int update_fstring_expr(struct tok_state *tok, char cur) {
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
case '!':
|
case '!':
|
||||||
case ':':
|
|
||||||
tok_mode->last_expr_end = strlen(tok->start);
|
tok_mode->last_expr_end = strlen(tok->start);
|
||||||
|
case ':':
|
||||||
|
if (tok_mode->last_expr_end == -1) {
|
||||||
|
tok_mode->last_expr_end = strlen(tok->start);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Py_UNREACHABLE();
|
Py_UNREACHABLE();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue