Andreas Stührk <andy-pyt...@hammerhartes.de> added the comment:
On Fri, Mar 4, 2011 at 9:30 PM, Terry J. Reedy <rep...@bugs.python.org> wrote:
> I agree with Martin (from 2000) that SyntaxError is not right either. Perhaps
> a new ParseError subclass thereof.
I added a new `ParserError` that inherits from `SyntaxError`.
> I presume REPL == read-eval-print-loop (from Google). Would a new error help
> such programs (like code.interact, or IDLE)?
Yes, I meant a read-eval-print-loop. A new error would help and if
it's a subclass of SyntaxError, they most likely need no changes at
all to handle that new error, as they have to deal with SyntaxErrors
anyway.
----------
Added file: http://bugs.python.org/file21387/issue11343.patch
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11343>
_______________________________________
diff -r a729dfdbd24b Doc/library/exceptions.rst
--- a/Doc/library/exceptions.rst Thu Mar 24 22:32:56 2011 +0200
+++ b/Doc/library/exceptions.rst Fri Mar 25 01:43:13 2011 +0100
@@ -289,6 +289,12 @@
This is a subclass of :exc:`IndentationError`.
+.. exception:: ParserError
+
+ Raised when the parser encounters an error due to internal limitations.
+ This is a subclass of :exc:`SyntaxError`.
+
+
.. exception:: SystemError
Raised when the interpreter finds an internal error, but the situation does
not
diff -r a729dfdbd24b Include/errcode.h
--- a/Include/errcode.h Thu Mar 24 22:32:56 2011 +0200
+++ b/Include/errcode.h Fri Mar 25 01:43:13 2011 +0100
@@ -30,6 +30,7 @@
#define E_EOLS 24 /* EOL in single-quoted string */
#define E_LINECONT 25 /* Unexpected characters after a line
continuation */
#define E_IDENTIFIER 26 /* Invalid characters in identifier */
+#define E_TOONESTED 27 /* Too many opening parens */
#ifdef __cplusplus
}
diff -r a729dfdbd24b Include/pyerrors.h
--- a/Include/pyerrors.h Thu Mar 24 22:32:56 2011 +0200
+++ b/Include/pyerrors.h Fri Mar 25 01:43:13 2011 +0100
@@ -149,6 +149,7 @@
PyAPI_DATA(PyObject *) PyExc_SyntaxError;
PyAPI_DATA(PyObject *) PyExc_IndentationError;
PyAPI_DATA(PyObject *) PyExc_TabError;
+PyAPI_DATA(PyObject *) PyExc_ParserError;
PyAPI_DATA(PyObject *) PyExc_ReferenceError;
PyAPI_DATA(PyObject *) PyExc_SystemError;
PyAPI_DATA(PyObject *) PyExc_SystemExit;
diff -r a729dfdbd24b Lib/test/exception_hierarchy.txt
--- a/Lib/test/exception_hierarchy.txt Thu Mar 24 22:32:56 2011 +0200
+++ b/Lib/test/exception_hierarchy.txt Fri Mar 25 01:43:13 2011 +0100
@@ -29,7 +29,8 @@
| +-- NotImplementedError
+-- SyntaxError
| +-- IndentationError
- | +-- TabError
+ | | +-- TabError
+ | +-- ParserError
+-- SystemError
+-- TypeError
+-- ValueError
diff -r a729dfdbd24b Lib/test/test_parser.py
--- a/Lib/test/test_parser.py Thu Mar 24 22:32:56 2011 +0200
+++ b/Lib/test/test_parser.py Fri Mar 25 01:43:13 2011 +0100
@@ -542,10 +542,7 @@
def test_trigger_memory_error(self):
e = self._nested_expression(100)
- print("Expecting 's_push: parser stack overflow' in next line",
- file=sys.stderr)
- sys.stderr.flush()
- self.assertRaises(MemoryError, parser.expr, e)
+ self.assertRaises(ParserError, parser.expr, e)
class STObjectTestCase(unittest.TestCase):
"""Test operations on ST objects themselves"""
diff -r a729dfdbd24b Objects/exceptions.c
--- a/Objects/exceptions.c Thu Mar 24 22:32:56 2011 +0200
+++ b/Objects/exceptions.c Fri Mar 25 01:43:13 2011 +0100
@@ -1063,6 +1063,14 @@
/*
+ * ParserError extends SyntaxError
+ */
+MiddlingExtendsException(PyExc_SyntaxError, ParserError, SyntaxError,
+ "Raised when the parser encounters an error due "
+ "to internal limitations.");
+
+
+/*
* LookupError extends Exception
*/
SimpleExtendsException(PyExc_Exception, LookupError,
@@ -1998,6 +2006,7 @@
PRE_INIT(SyntaxError)
PRE_INIT(IndentationError)
PRE_INIT(TabError)
+ PRE_INIT(ParserError)
PRE_INIT(LookupError)
PRE_INIT(IndexError)
PRE_INIT(KeyError)
@@ -2061,6 +2070,7 @@
POST_INIT(SyntaxError)
POST_INIT(IndentationError)
POST_INIT(TabError)
+ POST_INIT(ParserError)
POST_INIT(LookupError)
POST_INIT(IndexError)
POST_INIT(KeyError)
diff -r a729dfdbd24b Parser/parser.c
--- a/Parser/parser.c Thu Mar 24 22:32:56 2011 +0200
+++ b/Parser/parser.c Fri Mar 25 01:43:13 2011 +0100
@@ -39,8 +39,7 @@
{
register stackentry *top;
if (s->s_top == s->s_base) {
- fprintf(stderr, "s_push: parser stack overflow\n");
- return E_NOMEM;
+ return E_TOONESTED;
}
top = --s->s_top;
top->s_dfa = d;
diff -r a729dfdbd24b Python/pythonrun.c
--- a/Python/pythonrun.c Thu Mar 24 22:32:56 2011 +0200
+++ b/Python/pythonrun.c Fri Mar 25 01:43:13 2011 +0100
@@ -2052,6 +2052,10 @@
case E_IDENTIFIER:
msg = "invalid character in identifier";
break;
+ case E_TOONESTED:
+ errtype = PyExc_ParserError;
+ msg = "too many opening parens";
+ break;
default:
fprintf(stderr, "error=%d\n", err->error);
msg = "unknown parsing error";
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com