Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bd2b98

Browse files
committed
Merge 3.5 (Issue #24528)
2 parents c28e985 + 9dec035 commit 3bd2b98

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lib/test/test_coroutines.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ def test_badsyntax_9(self):
106106
with self.assertRaisesRegex(SyntaxError, 'invalid syntax'):
107107
import test.badsyntax_async9
108108

109+
def test_badsyntax_10(self):
110+
ns = {}
111+
for comp in {'(await a for a in b)',
112+
'[await a for a in b]',
113+
'{await a for a in b}',
114+
'{await a: c for a in b}'}:
115+
116+
with self.assertRaisesRegex( SyntaxError, 'await.*in comprehen'):
117+
exec('async def f():\n\t{}'.format(comp), ns, ns)
118+
109119

110120
class TokenizerRegrTest(unittest.TestCase):
111121

Python/compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3856,7 +3856,10 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
38563856
if (c->u->u_ste->ste_type != FunctionBlock)
38573857
return compiler_error(c, "'await' outside function");
38583858

3859-
/* this check won't be triggered while we have AWAIT token */
3859+
if (c->u->u_scope_type == COMPILER_SCOPE_COMPREHENSION)
3860+
return compiler_error(
3861+
c, "'await' expressions in comprehensions are not supported");
3862+
38603863
if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION)
38613864
return compiler_error(c, "'await' outside async function");
38623865

0 commit comments

Comments
 (0)