Skip to content

Commit 698b4b7

Browse files
[3.12] gh-112388: Fix an error that was causing the parser to try to overwrite tokenizer errors (GH-112410) (#112466)
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 7140716 commit 698b4b7

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

23102310
def test_invisible_characters(self):
23112311
self._check_error('print\x17("Hello")', "invalid non-printable character")
2312+
self._check_error(b"with(0,,):\n\x01", "invalid non-printable character")
23122313

23132314
def test_match_call_does_not_raise_syntax_error(self):
23142315
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
@@ -217,6 +217,10 @@ _PyPegen_tokenize_full_source_to_check_for_errors(Parser *p) {
217217
void *
218218
_PyPegen_raise_error(Parser *p, PyObject *errtype, int use_mark, const char *errmsg, ...)
219219
{
220+
// Bail out if we already have an error set.
221+
if (p->error_indicator && PyErr_Occurred()) {
222+
return NULL;
223+
}
220224
if (p->fill == 0) {
221225
va_list va;
222226
va_start(va, errmsg);

0 commit comments

Comments
 (0)