]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
don't restrict unexpected EOF errors to the first line (closes #12216)
authorBenjamin Peterson <benjamin@python.org>
Mon, 30 May 2011 16:12:38 +0000 (11:12 -0500)
committerBenjamin Peterson <benjamin@python.org>
Mon, 30 May 2011 16:12:38 +0000 (11:12 -0500)
Lib/test/test_grammar.py
Misc/NEWS
Parser/parsetok.c

index 9953363a0d1d27b0787582943266ee367090f798..32dc15ed32cb727f81309c507b17f0f2692cf5ff 100644 (file)
@@ -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
index fde085b527d33458dea6750952bf1fe40319aafd..0b9394565530eb0dc22f200221eea99f71de95d6 100644 (file)
--- 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.
 
index eef650ac5446a1ecb53ffa7a0b33140b8075d6b6..431a87cba7af2208af4045a62592fafa7a09398b 100644 (file)
@@ -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) {