Skip to content

Commit 0d0a9ea

Browse files
authored
[3.9] bpo-44409: Fix error location in tokenizer errors that happen during initialization (GH-26712). (GH-26723)
(cherry picked from commit 507ed6f) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
1 parent 7f02195 commit 0d0a9ea

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

Lib/test/test_exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def baz():
235235
""", 9, 20)
236236
check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4)
237237
check("(1+)", 1, 4)
238+
check(b"\xef\xbb\xbf#coding: utf8\nprint('\xe6\x88\x91')\n", 0, -1)
238239

239240
# Errors thrown by symtable.c
240241
check('x = [(yield i) for i in range(3)]', 1, 5)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix error location information for tokenizer errors raised on initialization
2+
of the tokenizer. Patch by Pablo Galindo.

Parser/pegen/pegen.c

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ static void
269269
raise_tokenizer_init_error(PyObject *filename)
270270
{
271271
if (!(PyErr_ExceptionMatches(PyExc_LookupError)
272+
|| PyErr_ExceptionMatches(PyExc_SyntaxError)
272273
|| PyErr_ExceptionMatches(PyExc_ValueError)
273274
|| PyErr_ExceptionMatches(PyExc_UnicodeDecodeError))) {
274275
return;

0 commit comments

Comments
 (0)