diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index e89d9401f2c397f..9abb545c0ad7900 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -972,6 +972,9 @@ def func2(): """ self._check_error(code, "invalid syntax") + def test_unexpected_line_continuation(self): + self._check_error('A.\u018a\\ ', "unexpected character after line continuation character") + def test_main(): support.run_unittest(SyntaxTestCase) from test import test_syntax diff --git a/Parser/pegen.c b/Parser/pegen.c index 188fd282b760436..be6441e6f70d4d1 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -835,7 +835,7 @@ expr_ty _PyPegen_name_token(Parser *p) { Token *t = _PyPegen_expect_token(p, NAME); - if (t == NULL) { + if (t == NULL || p->error_indicator) { return NULL; } char* s = PyBytes_AsString(t->bytes);