mirror of https://github.com/python/cpython
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>
This commit is contained in:
parent
1f515e8a10
commit
39d102c2ee
|
@ -220,6 +220,7 @@ var,PyExc_GeneratorExit,3.2,,
|
||||||
var,PyExc_IOError,3.2,,
|
var,PyExc_IOError,3.2,,
|
||||||
var,PyExc_ImportError,3.2,,
|
var,PyExc_ImportError,3.2,,
|
||||||
var,PyExc_ImportWarning,3.2,,
|
var,PyExc_ImportWarning,3.2,,
|
||||||
|
var,PyExc_IncompleteInputError,3.13,,
|
||||||
var,PyExc_IndentationError,3.2,,
|
var,PyExc_IndentationError,3.2,,
|
||||||
var,PyExc_IndexError,3.2,,
|
var,PyExc_IndexError,3.2,,
|
||||||
var,PyExc_InterruptedError,3.7,,
|
var,PyExc_InterruptedError,3.7,,
|
||||||
|
|
|
@ -108,6 +108,7 @@ PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
|
||||||
PyAPI_DATA(PyObject *) PyExc_SyntaxError;
|
PyAPI_DATA(PyObject *) PyExc_SyntaxError;
|
||||||
PyAPI_DATA(PyObject *) PyExc_IndentationError;
|
PyAPI_DATA(PyObject *) PyExc_IndentationError;
|
||||||
PyAPI_DATA(PyObject *) PyExc_TabError;
|
PyAPI_DATA(PyObject *) PyExc_TabError;
|
||||||
|
PyAPI_DATA(PyObject *) PyExc_IncompleteInputError;
|
||||||
PyAPI_DATA(PyObject *) PyExc_ReferenceError;
|
PyAPI_DATA(PyObject *) PyExc_ReferenceError;
|
||||||
PyAPI_DATA(PyObject *) PyExc_SystemError;
|
PyAPI_DATA(PyObject *) PyExc_SystemError;
|
||||||
PyAPI_DATA(PyObject *) PyExc_SystemExit;
|
PyAPI_DATA(PyObject *) PyExc_SystemExit;
|
||||||
|
|
|
@ -65,9 +65,10 @@ def _maybe_compile(compiler, source, filename, symbol):
|
||||||
try:
|
try:
|
||||||
compiler(source + "\n", filename, symbol)
|
compiler(source + "\n", filename, symbol)
|
||||||
return None
|
return None
|
||||||
|
except IncompleteInputError as e:
|
||||||
|
return None
|
||||||
except SyntaxError as e:
|
except SyntaxError as e:
|
||||||
if "incomplete input" in str(e):
|
pass
|
||||||
return None
|
|
||||||
# fallthrough
|
# fallthrough
|
||||||
|
|
||||||
return compiler(source, filename, symbol, incomplete_input=False)
|
return compiler(source, filename, symbol, incomplete_input=False)
|
||||||
|
|
|
@ -44,6 +44,7 @@ BaseException
|
||||||
├── StopAsyncIteration
|
├── StopAsyncIteration
|
||||||
├── StopIteration
|
├── StopIteration
|
||||||
├── SyntaxError
|
├── SyntaxError
|
||||||
|
│ └── IncompleteInputError
|
||||||
│ └── IndentationError
|
│ └── IndentationError
|
||||||
│ └── TabError
|
│ └── TabError
|
||||||
├── SystemError
|
├── SystemError
|
||||||
|
|
|
@ -567,7 +567,8 @@ class CompatPickleTests(unittest.TestCase):
|
||||||
RecursionError,
|
RecursionError,
|
||||||
EncodingWarning,
|
EncodingWarning,
|
||||||
BaseExceptionGroup,
|
BaseExceptionGroup,
|
||||||
ExceptionGroup):
|
ExceptionGroup,
|
||||||
|
IncompleteInputError):
|
||||||
continue
|
continue
|
||||||
if exc is not OSError and issubclass(exc, OSError):
|
if exc is not OSError and issubclass(exc, OSError):
|
||||||
self.assertEqual(reverse_mapping('builtins', name),
|
self.assertEqual(reverse_mapping('builtins', name),
|
||||||
|
|
|
@ -261,6 +261,7 @@ SYMBOL_NAMES = (
|
||||||
"PyExc_IOError",
|
"PyExc_IOError",
|
||||||
"PyExc_ImportError",
|
"PyExc_ImportError",
|
||||||
"PyExc_ImportWarning",
|
"PyExc_ImportWarning",
|
||||||
|
"PyExc_IncompleteInputError",
|
||||||
"PyExc_IndentationError",
|
"PyExc_IndentationError",
|
||||||
"PyExc_IndexError",
|
"PyExc_IndexError",
|
||||||
"PyExc_InterruptedError",
|
"PyExc_InterruptedError",
|
||||||
|
|
|
@ -2485,3 +2485,5 @@
|
||||||
[function._Py_SetRefcnt]
|
[function._Py_SetRefcnt]
|
||||||
added = '3.13'
|
added = '3.13'
|
||||||
abi_only = true
|
abi_only = true
|
||||||
|
[data.PyExc_IncompleteInputError]
|
||||||
|
added = '3.13'
|
||||||
|
|
|
@ -2566,6 +2566,11 @@ MiddlingExtendsException(PyExc_SyntaxError, IndentationError, SyntaxError,
|
||||||
MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError,
|
MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError,
|
||||||
"Improper mixture of spaces and tabs.");
|
"Improper mixture of spaces and tabs.");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IncompleteInputError extends SyntaxError
|
||||||
|
*/
|
||||||
|
MiddlingExtendsException(PyExc_SyntaxError, IncompleteInputError, SyntaxError,
|
||||||
|
"incomplete input.");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LookupError extends Exception
|
* LookupError extends Exception
|
||||||
|
@ -3635,6 +3640,7 @@ static struct static_exception static_exceptions[] = {
|
||||||
|
|
||||||
// Level 4: Other subclasses
|
// Level 4: Other subclasses
|
||||||
ITEM(IndentationError), // base: SyntaxError(Exception)
|
ITEM(IndentationError), // base: SyntaxError(Exception)
|
||||||
|
ITEM(IncompleteInputError), // base: SyntaxError(Exception)
|
||||||
ITEM(IndexError), // base: LookupError(Exception)
|
ITEM(IndexError), // base: LookupError(Exception)
|
||||||
ITEM(KeyError), // base: LookupError(Exception)
|
ITEM(KeyError), // base: LookupError(Exception)
|
||||||
ITEM(ModuleNotFoundError), // base: ImportError(Exception)
|
ITEM(ModuleNotFoundError), // base: ImportError(Exception)
|
||||||
|
|
|
@ -830,6 +830,7 @@ EXPORT_DATA(PyExc_FutureWarning)
|
||||||
EXPORT_DATA(PyExc_GeneratorExit)
|
EXPORT_DATA(PyExc_GeneratorExit)
|
||||||
EXPORT_DATA(PyExc_ImportError)
|
EXPORT_DATA(PyExc_ImportError)
|
||||||
EXPORT_DATA(PyExc_ImportWarning)
|
EXPORT_DATA(PyExc_ImportWarning)
|
||||||
|
EXPORT_DATA(PyExc_IncompleteInputError)
|
||||||
EXPORT_DATA(PyExc_IndentationError)
|
EXPORT_DATA(PyExc_IndentationError)
|
||||||
EXPORT_DATA(PyExc_IndexError)
|
EXPORT_DATA(PyExc_IndexError)
|
||||||
EXPORT_DATA(PyExc_InterruptedError)
|
EXPORT_DATA(PyExc_InterruptedError)
|
||||||
|
|
|
@ -844,7 +844,7 @@ _PyPegen_run_parser(Parser *p)
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
if ((p->flags & PyPARSE_ALLOW_INCOMPLETE_INPUT) && _is_end_of_source(p)) {
|
if ((p->flags & PyPARSE_ALLOW_INCOMPLETE_INPUT) && _is_end_of_source(p)) {
|
||||||
PyErr_Clear();
|
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)) {
|
if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_SyntaxError)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -197,6 +197,7 @@ Objects/exceptions.c - _PyExc_AttributeError -
|
||||||
Objects/exceptions.c - _PyExc_SyntaxError -
|
Objects/exceptions.c - _PyExc_SyntaxError -
|
||||||
Objects/exceptions.c - _PyExc_IndentationError -
|
Objects/exceptions.c - _PyExc_IndentationError -
|
||||||
Objects/exceptions.c - _PyExc_TabError -
|
Objects/exceptions.c - _PyExc_TabError -
|
||||||
|
Objects/exceptions.c - _PyExc_IncompleteInputError -
|
||||||
Objects/exceptions.c - _PyExc_LookupError -
|
Objects/exceptions.c - _PyExc_LookupError -
|
||||||
Objects/exceptions.c - _PyExc_IndexError -
|
Objects/exceptions.c - _PyExc_IndexError -
|
||||||
Objects/exceptions.c - _PyExc_KeyError -
|
Objects/exceptions.c - _PyExc_KeyError -
|
||||||
|
@ -261,6 +262,7 @@ Objects/exceptions.c - PyExc_AttributeError -
|
||||||
Objects/exceptions.c - PyExc_SyntaxError -
|
Objects/exceptions.c - PyExc_SyntaxError -
|
||||||
Objects/exceptions.c - PyExc_IndentationError -
|
Objects/exceptions.c - PyExc_IndentationError -
|
||||||
Objects/exceptions.c - PyExc_TabError -
|
Objects/exceptions.c - PyExc_TabError -
|
||||||
|
Objects/exceptions.c - PyExc_IncompleteInputError -
|
||||||
Objects/exceptions.c - PyExc_LookupError -
|
Objects/exceptions.c - PyExc_LookupError -
|
||||||
Objects/exceptions.c - PyExc_IndexError -
|
Objects/exceptions.c - PyExc_IndexError -
|
||||||
Objects/exceptions.c - PyExc_KeyError -
|
Objects/exceptions.c - PyExc_KeyError -
|
||||||
|
|
Can't render this file because it has a wrong number of fields in line 4.
|
Loading…
Reference in New Issue