]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-113744: Add a new IncompleteInputError exception to improve incomplete input detec...
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Tue, 30 Jan 2024 16:21:30 +0000 (16:21 +0000)
committerGitHub <noreply@github.com>
Tue, 30 Jan 2024 16:21:30 +0000 (16:21 +0000)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Doc/data/stable_abi.dat
Include/pyerrors.h
Lib/codeop.py
Lib/test/exception_hierarchy.txt
Lib/test/test_pickle.py
Lib/test/test_stable_abi_ctypes.py
Misc/stable_abi.toml
Objects/exceptions.c
PC/python3dll.c
Parser/pegen.c
Tools/c-analyzer/cpython/globals-to-fix.tsv

index 811b1bd84d24174e068ec489cc16c4a24758c5e8..da28a2be60bc1bc105023ea35371a50717f403e0 100644 (file)
@@ -220,6 +220,7 @@ var,PyExc_GeneratorExit,3.2,,
 var,PyExc_IOError,3.2,,
 var,PyExc_ImportError,3.2,,
 var,PyExc_ImportWarning,3.2,,
+var,PyExc_IncompleteInputError,3.13,,
 var,PyExc_IndentationError,3.2,,
 var,PyExc_IndexError,3.2,,
 var,PyExc_InterruptedError,3.7,,
index 5d0028c116e2d862948042746734e252e4aed0f6..68d7985dac8876bfc588ffb05d46bfd643685a41 100644 (file)
@@ -108,6 +108,7 @@ PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
 PyAPI_DATA(PyObject *) PyExc_SyntaxError;
 PyAPI_DATA(PyObject *) PyExc_IndentationError;
 PyAPI_DATA(PyObject *) PyExc_TabError;
+PyAPI_DATA(PyObject *) PyExc_IncompleteInputError;
 PyAPI_DATA(PyObject *) PyExc_ReferenceError;
 PyAPI_DATA(PyObject *) PyExc_SystemError;
 PyAPI_DATA(PyObject *) PyExc_SystemExit;
index 91146be2c438e2c88f511f1eaf9210eb1927b83b..6ad60e7f85098d814532c2712e457664f18c5b04 100644 (file)
@@ -65,9 +65,10 @@ def _maybe_compile(compiler, source, filename, symbol):
             try:
                 compiler(source + "\n", filename, symbol)
                 return None
+            except IncompleteInputError as e:
+                return None
             except SyntaxError as e:
-                if "incomplete input" in str(e):
-                    return None
+                pass
                 # fallthrough
 
     return compiler(source, filename, symbol, incomplete_input=False)
index 1eca123be0fecbfe8276c3f33c0df91cb952f2ff..217ee15d4c8af54322e860c6e5cac593c9623462 100644 (file)
@@ -44,6 +44,7 @@ BaseException
       ├── StopAsyncIteration
       ├── StopIteration
       ├── SyntaxError
+      │    └── IncompleteInputError
       │    └── IndentationError
       │         └── TabError
       ├── SystemError
index b2245ddf72f7085eaad98debb876f3143fa78d9d..5e187e5189d11795467654ecefe8f6e3409aee6f 100644 (file)
@@ -567,7 +567,8 @@ class CompatPickleTests(unittest.TestCase):
                            RecursionError,
                            EncodingWarning,
                            BaseExceptionGroup,
-                           ExceptionGroup):
+                           ExceptionGroup,
+                           IncompleteInputError):
                     continue
                 if exc is not OSError and issubclass(exc, OSError):
                     self.assertEqual(reverse_mapping('builtins', name),
index 90d4527283842088caafe9a3ab99477a0f761a9a..054e7f0feb1a19db517daa978fcda3a94f5cb085 100644 (file)
@@ -261,6 +261,7 @@ SYMBOL_NAMES = (
     "PyExc_IOError",
     "PyExc_ImportError",
     "PyExc_ImportWarning",
+    "PyExc_IncompleteInputError",
     "PyExc_IndentationError",
     "PyExc_IndexError",
     "PyExc_InterruptedError",
index 2e6b0fff9cd7704c3817c6132c33ef96af447b6a..ae19d25809ec86741b9f8a3e96aefa94e5d2970c 100644 (file)
 [function._Py_SetRefcnt]
     added = '3.13'
     abi_only = true
+[data.PyExc_IncompleteInputError]
+    added = '3.13'
index a685ed803cd02dbd9cdd661324cf97171f0ade8e..cff55d05163b6ba811899b9392f05436937a805e 100644 (file)
@@ -2566,6 +2566,11 @@ MiddlingExtendsException(PyExc_SyntaxError, IndentationError, SyntaxError,
 MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError,
                          "Improper mixture of spaces and tabs.");
 
+/*
+ *    IncompleteInputError extends SyntaxError
+ */
+MiddlingExtendsException(PyExc_SyntaxError, IncompleteInputError, SyntaxError,
+                         "incomplete input.");
 
 /*
  *    LookupError extends Exception
@@ -3635,6 +3640,7 @@ static struct static_exception static_exceptions[] = {
 
     // Level 4: Other subclasses
     ITEM(IndentationError), // base: SyntaxError(Exception)
+    ITEM(IncompleteInputError), // base: SyntaxError(Exception)
     ITEM(IndexError),  // base: LookupError(Exception)
     ITEM(KeyError),  // base: LookupError(Exception)
     ITEM(ModuleNotFoundError), // base: ImportError(Exception)
index 07aa84c91f9fc7fa0ead17831d135672140f9fe4..09ecf98fe56ea62b33c07f56fd596a3c153382b9 100755 (executable)
@@ -830,6 +830,7 @@ EXPORT_DATA(PyExc_FutureWarning)
 EXPORT_DATA(PyExc_GeneratorExit)
 EXPORT_DATA(PyExc_ImportError)
 EXPORT_DATA(PyExc_ImportWarning)
+EXPORT_DATA(PyExc_IncompleteInputError)
 EXPORT_DATA(PyExc_IndentationError)
 EXPORT_DATA(PyExc_IndexError)
 EXPORT_DATA(PyExc_InterruptedError)
index 7766253a76066f07c9afb2e1c6b605484f004e91..3d3e64559403b16a6a01450eb74bc191d8a11c35 100644 (file)
@@ -844,7 +844,7 @@ _PyPegen_run_parser(Parser *p)
     if (res == NULL) {
         if ((p->flags & PyPARSE_ALLOW_INCOMPLETE_INPUT) &&  _is_end_of_source(p)) {
             PyErr_Clear();
-            return RAISE_SYNTAX_ERROR("incomplete input");
+            return _PyPegen_raise_error(p, PyExc_IncompleteInputError, 0, "incomplete input");
         }
         if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_SyntaxError)) {
             return NULL;
index e3a1b5d532bda2a1c11b8bf221ce34383fb641a4..0b02ad01d399836f58f74d9a8f6b904ed0402cb7 100644 (file)
@@ -197,6 +197,7 @@ Objects/exceptions.c        -       _PyExc_AttributeError   -
 Objects/exceptions.c   -       _PyExc_SyntaxError      -
 Objects/exceptions.c   -       _PyExc_IndentationError -
 Objects/exceptions.c   -       _PyExc_TabError -
+Objects/exceptions.c   -       _PyExc_IncompleteInputError     -
 Objects/exceptions.c   -       _PyExc_LookupError      -
 Objects/exceptions.c   -       _PyExc_IndexError       -
 Objects/exceptions.c   -       _PyExc_KeyError -
@@ -261,6 +262,7 @@ Objects/exceptions.c        -       PyExc_AttributeError    -
 Objects/exceptions.c   -       PyExc_SyntaxError       -
 Objects/exceptions.c   -       PyExc_IndentationError  -
 Objects/exceptions.c   -       PyExc_TabError  -
+Objects/exceptions.c   -       PyExc_IncompleteInputError      -
 Objects/exceptions.c   -       PyExc_LookupError       -
 Objects/exceptions.c   -       PyExc_IndexError        -
 Objects/exceptions.c   -       PyExc_KeyError  -