diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-06-14 16:46:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 16:46:11 (GMT) |
commit | 507ed6fa1d6661e0f8e6d3282764aa9625a99594 (patch) | |
tree | 12f906c723fcd0c24383725fa1d5899cc8c8429f | |
parent | cc8ecf6864375994899fd79d601ab05d0df9edbf (diff) | |
download | cpython-507ed6fa1d6661e0f8e6d3282764aa9625a99594.zip cpython-507ed6fa1d6661e0f8e6d3282764aa9625a99594.tar.gz cpython-507ed6fa1d6661e0f8e6d3282764aa9625a99594.tar.bz2 |
bpo-44409: Fix error location in tokenizer errors that happen during initialization (GH-26712)
-rw-r--r-- | Lib/test/test_exceptions.py | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2021-06-13-23-12-18.bpo-44409.eW4LS-.rst | 2 | ||||
-rw-r--r-- | Parser/pegen.c | 1 |
3 files changed, 4 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 9cb5466..d444a12 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -246,6 +246,7 @@ class ExceptionTests(unittest.TestCase): check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4) check("(1+)", 1, 4) check("[interesting\nfoo()\n", 1, 1) + 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 index 0000000..0f204ed --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-06-13-23-12-18.bpo-44409.eW4LS-.rst @@ -0,0 +1,2 @@ +Fix error location information for tokenizer errors raised on initialization +of the tokenizer. Patch by Pablo Galindo. diff --git a/Parser/pegen.c b/Parser/pegen.c index 1941244..615047c 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -283,6 +283,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; |