Skip to content

Commit 39d102c

Browse files
authored
gh-113744: Add a new IncompleteInputError exception to improve incomplete input detection in the codeop module (#113745)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent 1f515e8 commit 39d102c

File tree

11 files changed

+21
-4
lines changed

11 files changed

+21
-4
lines changed

Doc/data/stable_abi.dat

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/pyerrors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
108108
PyAPI_DATA(PyObject *) PyExc_SyntaxError;
109109
PyAPI_DATA(PyObject *) PyExc_IndentationError;
110110
PyAPI_DATA(PyObject *) PyExc_TabError;
111+
PyAPI_DATA(PyObject *) PyExc_IncompleteInputError;
111112
PyAPI_DATA(PyObject *) PyExc_ReferenceError;
112113
PyAPI_DATA(PyObject *) PyExc_SystemError;
113114
PyAPI_DATA(PyObject *) PyExc_SystemExit;

Lib/codeop.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ def _maybe_compile(compiler, source, filename, symbol):
6565
try:
6666
compiler(source + "\n", filename, symbol)
6767
return None
68+
except IncompleteInputError as e:
69+
return None
6870
except SyntaxError as e:
69-
if "incomplete input" in str(e):
70-
return None
71+
pass
7172
# fallthrough
7273

7374
return compiler(source, filename, symbol, incomplete_input=False)

Lib/test/exception_hierarchy.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ BaseException
4444
├── StopAsyncIteration
4545
├── StopIteration
4646
├── SyntaxError
47+
│ └── IncompleteInputError
4748
│ └── IndentationError
4849
│ └── TabError
4950
├── SystemError

Lib/test/test_pickle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ def test_exceptions(self):
567567
RecursionError,
568568
EncodingWarning,
569569
BaseExceptionGroup,
570-
ExceptionGroup):
570+
ExceptionGroup,
571+
IncompleteInputError):
571572
continue
572573
if exc is not OSError and issubclass(exc, OSError):
573574
self.assertEqual(reverse_mapping('builtins', name),

Lib/test/test_stable_abi_ctypes.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Misc/stable_abi.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,3 +2485,5 @@
24852485
[function._Py_SetRefcnt]
24862486
added = '3.13'
24872487
abi_only = true
2488+
[data.PyExc_IncompleteInputError]
2489+
added = '3.13'

Objects/exceptions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,11 @@ MiddlingExtendsException(PyExc_SyntaxError, IndentationError, SyntaxError,
25662566
MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError,
25672567
"Improper mixture of spaces and tabs.");
25682568

2569+
/*
2570+
* IncompleteInputError extends SyntaxError
2571+
*/
2572+
MiddlingExtendsException(PyExc_SyntaxError, IncompleteInputError, SyntaxError,
2573+
"incomplete input.");
25692574

25702575
/*
25712576
* LookupError extends Exception
@@ -3635,6 +3640,7 @@ static struct static_exception static_exceptions[] = {
36353640

36363641
// Level 4: Other subclasses
36373642
ITEM(IndentationError), // base: SyntaxError(Exception)
3643+
ITEM(IncompleteInputError), // base: SyntaxError(Exception)
36383644
ITEM(IndexError), // base: LookupError(Exception)
36393645
ITEM(KeyError), // base: LookupError(Exception)
36403646
ITEM(ModuleNotFoundError), // base: ImportError(Exception)

PC/python3dll.c

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Parser/pegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ _PyPegen_run_parser(Parser *p)
844844
if (res == NULL) {
845845
if ((p->flags & PyPARSE_ALLOW_INCOMPLETE_INPUT) && _is_end_of_source(p)) {
846846
PyErr_Clear();
847-
return RAISE_SYNTAX_ERROR("incomplete input");
847+
return _PyPegen_raise_error(p, PyExc_IncompleteInputError, 0, "incomplete input");
848848
}
849849
if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_SyntaxError)) {
850850
return NULL;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy