Skip to content

Commit 507ed6f

Browse files
authored
bpo-44409: Fix error location in tokenizer errors that happen during initialization (GH-26712)
1 parent cc8ecf6 commit 507ed6f

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
@@ -246,6 +246,7 @@ def baz():
246246
check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4)
247247
check("(1+)", 1, 4)
248248
check("[interesting\nfoo()\n", 1, 1)
249+
check(b"\xef\xbb\xbf#coding: utf8\nprint('\xe6\x88\x91')\n", 0, -1)
249250

250251
# Errors thrown by symtable.c
251252
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.c

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ static void
283283
raise_tokenizer_init_error(PyObject *filename)
284284
{
285285
if (!(PyErr_ExceptionMatches(PyExc_LookupError)
286+
|| PyErr_ExceptionMatches(PyExc_SyntaxError)
286287
|| PyErr_ExceptionMatches(PyExc_ValueError)
287288
|| PyErr_ExceptionMatches(PyExc_UnicodeDecodeError))) {
288289
return;

0 commit comments

Comments
 (0)