]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-44409: Fix error location in tokenizer errors that happen during initializa...
authorPablo Galindo <Pablogsal@gmail.com>
Mon, 14 Jun 2021 17:07:51 +0000 (18:07 +0100)
committerGitHub <noreply@github.com>
Mon, 14 Jun 2021 17:07:51 +0000 (18:07 +0100)
(cherry picked from commit 507ed6fa1d6661e0f8e6d3282764aa9625a99594)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Lib/test/test_exceptions.py
Misc/NEWS.d/next/Core and Builtins/2021-06-13-23-12-18.bpo-44409.eW4LS-.rst [new file with mode: 0644]
Parser/pegen/pegen.c

index 8d125b57ad6d5a8b98f82e4f0b274f611b2bc9fc..0f7b7f84809d96a2d6429947e050246d15e92259 100644 (file)
@@ -235,6 +235,7 @@ class ExceptionTests(unittest.TestCase):
             """, 9, 20)
         check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4)
         check("(1+)", 1, 4)
+        check(b"\xef\xbb\xbf#coding: utf8\nprint('\xe6\x88\x91')\n", 0, -1)
 
         # Errors thrown by symtable.c
         check('x = [(yield i) for i in range(3)]', 1, 5)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-06-13-23-12-18.bpo-44409.eW4LS-.rst b/Misc/NEWS.d/next/Core and Builtins/2021-06-13-23-12-18.bpo-44409.eW4LS-.rst
new file mode 100644 (file)
index 0000000..0f204ed
--- /dev/null
@@ -0,0 +1,2 @@
+Fix error location information for tokenizer errors raised on initialization
+of the tokenizer. Patch by Pablo Galindo.
index 111009af63e22a2dee4778022f341637f150c9de..bf53214b4d06374cfa68675e78ef3c6d370715f2 100644 (file)
@@ -269,6 +269,7 @@ static void
 raise_tokenizer_init_error(PyObject *filename)
 {
     if (!(PyErr_ExceptionMatches(PyExc_LookupError)
+          || PyErr_ExceptionMatches(PyExc_SyntaxError)
           || PyErr_ExceptionMatches(PyExc_ValueError)
           || PyErr_ExceptionMatches(PyExc_UnicodeDecodeError))) {
         return;