Skip to content

Commit 43b081b

Browse files
[3.11] gh-112388: Fix an error that was causing the parser to try to overwrite tokenizer errors (GH-112410) (#112467)
gh-112388: Fix an error that was causing the parser to try to overwrite tokenizer errors (GH-112410) (cherry picked from commit 2c8b191) Signed-off-by: Pablo Galindo <[email protected]> Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent 054d18e commit 43b081b

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,7 @@ def test_error_string_literal(self):
21522152

21532153
def test_invisible_characters(self):
21542154
self._check_error('print\x17("Hello")', "invalid non-printable character")
2155+
self._check_error(b"with(0,,):\n\x01", "invalid non-printable character")
21552156

21562157
def test_match_call_does_not_raise_syntax_error(self):
21572158
code = """
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an error that was causing the parser to try to overwrite tokenizer
2+
errors. Patch by pablo Galindo

Parser/pegen_errors.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ _PyPegen_tokenize_full_source_to_check_for_errors(Parser *p) {
212212
void *
213213
_PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...)
214214
{
215+
// Bail out if we already have an error set.
216+
if (p->error_indicator && PyErr_Occurred()) {
217+
return NULL;
218+
}
215219
if (p->fill == 0) {
216220
va_list va;
217221
va_start(va, errmsg);

0 commit comments

Comments
 (0)