[Python-checkins] cpython: don't restrict unexpected EOF errors to the first line (closes #12216)
benjamin.peterson
python-checkins at python.org
Mon May 30 18:15:12 CEST 2011
http://hg.python.org/cpython/rev/fefca6548732
changeset: 70523:fefca6548732
user: Benjamin Peterson <benjamin at python.org>
date: Mon May 30 11:12:38 2011 -0500
summary:
don't restrict unexpected EOF errors to the first line (closes #12216)
files:
Lib/test/test_grammar.py | 7 +++++++
Misc/NEWS | 2 ++
Parser/parsetok.c | 2 +-
3 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -125,6 +125,13 @@
self.assertTrue(x is Ellipsis)
self.assertRaises(SyntaxError, eval, ".. .")
+ def test_eof_error(self):
+ samples = ("def foo(", "\ndef foo(", "def foo(\n")
+ for s in samples:
+ with self.assertRaises(SyntaxError) as cm:
+ compile(s, "<test>", "exec")
+ self.assertIn("unexpected EOF", str(cm.exception))
+
class GrammarTests(unittest.TestCase):
# single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
Core and Builtins
-----------------
+- Issue #12216: Allow unexpected EOF errors to happen on any line of the file.
+
- Issue #12199: The TryExcept and TryFinally and AST nodes have been unified
into a Try node.
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -232,7 +232,7 @@
PyParser_Delete(ps);
if (n == NULL) {
- if (tok->lineno <= 1 && tok->done == E_EOF)
+ if (tok->done == E_EOF)
err_ret->error = E_EOF;
err_ret->lineno = tok->lineno;
if (tok->buf != NULL) {
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list