don't restrict unexpected EOF errors to the first line (closes #12216)

This commit is contained in:
Benjamin Peterson 2011-05-30 11:12:38 -05:00
parent c8507bfe9c
commit 758888d437
3 changed files with 10 additions and 1 deletions

View File

@ -125,6 +125,13 @@ the \'lazy\' dog.\n\
self.assertTrue(x is Ellipsis) self.assertTrue(x is Ellipsis)
self.assertRaises(SyntaxError, eval, ".. .") 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): class GrammarTests(unittest.TestCase):
# single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE # single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE

View File

@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins 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 - Issue #12199: The TryExcept and TryFinally and AST nodes have been unified
into a Try node. into a Try node.

View File

@ -232,7 +232,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
PyParser_Delete(ps); PyParser_Delete(ps);
if (n == NULL) { if (n == NULL) {
if (tok->lineno <= 1 && tok->done == E_EOF) if (tok->done == E_EOF)
err_ret->error = E_EOF; err_ret->error = E_EOF;
err_ret->lineno = tok->lineno; err_ret->lineno = tok->lineno;
if (tok->buf != NULL) { if (tok->buf != NULL) {