summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-05-30 16:12:38 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-05-30 16:12:38 (GMT)
commit758888d437c4c2d398ec322ff1596e1620f5f0dd (patch)
tree0d8f30a733d4a4afd42b3700d1433ef00f2fc5f3
parentc8507bfe9cd581de1b324af92bf255a86a0437b0 (diff)
downloadcpython-758888d437c4c2d398ec322ff1596e1620f5f0dd.zip
cpython-758888d437c4c2d398ec322ff1596e1620f5f0dd.tar.gz
cpython-758888d437c4c2d398ec322ff1596e1620f5f0dd.tar.bz2
don't restrict unexpected EOF errors to the first line (closes #12216)
-rw-r--r--Lib/test/test_grammar.py7
-rw-r--r--Misc/NEWS2
-rw-r--r--Parser/parsetok.c2
3 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 9953363..32dc15e 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -125,6 +125,13 @@ the \'lazy\' dog.\n\
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
index fde085b..0b93945 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
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
index eef650a..431a87c 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -232,7 +232,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
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) {