Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.6
Changeset: r93956:e8e5e733ff62
Date: 2018-03-05 00:19 +0100
http://bitbucket.org/pypy/pypy/changeset/e8e5e733ff62/
Log: More checks for forbidden 'await'
diff --git a/pypy/interpreter/astcompiler/codegen.py
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -283,6 +283,10 @@
def _get_code_flags(self):
return 0
+ def _check_async_function(self):
+ """Returns true if 'await' is allowed."""
+ return False
+
def _handle_body(self, body):
"""Compile a list of statements, handling doc strings if needed."""
if body:
@@ -1087,6 +1091,8 @@
self.emit_op(ops.YIELD_FROM)
def visit_Await(self, aw):
+ if not self._check_async_function():
+ self.error("'await' outside async function", aw)
self.update_position(aw.lineno)
aw.value.walkabout(self)
self.emit_op(ops.GET_AWAITABLE)
@@ -1752,6 +1758,9 @@
for i in range(start, len(func.body)):
func.body[i].walkabout(self)
+ def _check_async_function(self):
+ return True
+
class LambdaCodeGenerator(AbstractFunctionCodeGenerator):
def _compile(self, lam):
@@ -1780,6 +1789,9 @@
def _end_comp(self):
self.emit_op(ops.RETURN_VALUE)
+ def _check_async_function(self):
+ return True
+
class GenExpCodeGenerator(ComprehensionCodeGenerator):
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1163,6 +1163,14 @@
"""
self.simple_test(source, "None", None)
+ def test_await_in_nested(self):
+ source = """if 1:
+ async def foo():
+ def bar():
+ [i for i in await items]
+ """
+ e = py.test.raises(SyntaxError, self.simple_test, source, "None", None)
+
def test_load_classderef(self):
source = """if 1:
def f():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit