From 9c90d09b796286cccd3e71706158b0fc4520cf6e Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Sat, 22 Apr 2023 03:45:54 +0800 Subject: [PATCH] do not use `tok_mode` at call_invalid_rules mode --- Lib/test/test_fstring.py | 13 +++++++++++++ Parser/action_helpers.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 0e71de85f16b9c..238d6e0be04115 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -1532,5 +1532,18 @@ def test_syntax_error_for_starred_expressions(self): "f-string: expecting a valid expression after '{'"): compile("f'{**a}'", "?", "exec") + def test_semicolon(self): + self.assertAllRaise(SyntaxError, + "f-string: expecting a valid expression after '{'", + ["f'{_=}{;", + "f'{1=}{+;'", + "f'{1=}{2}{;'", + ]) + self.assertAllRaise(SyntaxError, + "f-string: expecting '=', or '!', or ':', or '}'", + ["f'{1=}{1;'", + "f'{1=}{1;}'", + ]) + if __name__ == '__main__': unittest.main() diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c index 55c0f6fdd620f4..434147abf03cf0 100644 --- a/Parser/action_helpers.c +++ b/Parser/action_helpers.c @@ -1415,7 +1415,7 @@ expr_ty _PyPegen_formatted_value(Parser *p, expr_ty expression, Token *debug, ex end_col_offset, arena ); - if (debug) { + if (debug && !p->call_invalid_rules) { /* Find the non whitespace token after the "=" */ int debug_end_line, debug_end_offset;