Author: Raffael Tfirst <raffael.tfi...@gmail.com> Branch: py3.5-async Changeset: r85659:3700b8062272 Date: 2016-07-11 19:33 +0200 http://bitbucket.org/pypy/pypy/changeset/3700b8062272/
Log: Throw SyntaxError if 'await' outside [async] function (fixes test_invalid_2,4,5,8 in test_syntax) diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py --- a/pypy/interpreter/astcompiler/symtable.py +++ b/pypy/interpreter/astcompiler/symtable.py @@ -89,10 +89,15 @@ raise SyntaxError("'yield' outside function", yield_node.lineno, yield_node.col_offset) - def note_yieldFrom(self, yield_node): + def note_yieldFrom(self, yieldFrom_node): """Called when a yield from is found.""" - raise SyntaxError("'yield' outside function", yield_node.lineno, - yield_node.col_offset) + raise SyntaxError("'yield' outside function", yieldFrom_node.lineno, + yieldFrom_node.col_offset) + + def note_await(self, await_node): + """Called when await is found.""" + raise SyntaxError("'await' outside function", await_node.lineno, + await_node.col_offset) def note_return(self, ret): """Called when a return statement is found.""" @@ -229,6 +234,10 @@ def __init__(self): Scope.__init__(self, "top") + def note_await(self, await_node): + raise SyntaxError("'await' outside async function", await_node.lineno, + await_node.col_offset) + class FunctionScope(Scope): @@ -259,6 +268,10 @@ self.is_generator = True if self._in_try_body_depth > 0: self.has_yield_inside_try = True + + def note_await(self, await_node): + raise SyntaxError("'await' outside async function", await_node.lineno, + await_node.col_offset) def note_return(self, ret): if ret.value: @@ -304,6 +317,10 @@ def note_yieldFrom(self, yield_node): raise SyntaxError("'yield from' inside async function", yield_node.lineno, yield_node.col_offset) + + def note_await(self, await_node): + pass + class ClassScope(Scope): @@ -410,6 +427,10 @@ func.args.walkabout(self) self.visit_sequence(func.body) self.pop_scope() + + def visit_Await(self, aw): + self.scope.note_await(aw) + ast.GenericASTVisitor.visit_Await(self, aw) def visit_Return(self, ret): self.scope.note_return(ret) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit