Skip to content

Commit 2c8b191

Browse files
authored
gh-112388: Fix an error that was causing the parser to try to overwrite tokenizer errors (#112410)
Signed-off-by: Pablo Galindo <[email protected]>
1 parent 967f2a3 commit 2c8b191

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
@@ -2349,6 +2349,7 @@ def test_error_string_literal(self):
23492349

23502350
def test_invisible_characters(self):
23512351
self._check_error('print\x17("Hello")', "invalid non-printable character")
2352+
self._check_error(b"with(0,,):\n\x01", "invalid non-printable character")
23522353

23532354
def test_match_call_does_not_raise_syntax_error(self):
23542355
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
@@ -219,6 +219,10 @@ _PyPegen_tokenize_full_source_to_check_for_errors(Parser *p) {
219219
void *
220220
_PyPegen_raise_error(Parser *p, PyObject *errtype, int use_mark, const char *errmsg, ...)
221221
{
222+
// Bail out if we already have an error set.
223+
if (p->error_indicator && PyErr_Occurred()) {
224+
return NULL;
225+
}
222226
if (p->fill == 0) {
223227
va_list va;
224228
va_start(va, errmsg);

0 commit comments

Comments
 (0)