Add 'yield' inside async function' for Python 3.5.

This commit is contained in:
Dave Halter
2017-08-05 22:33:11 +02:00
parent 94570acef7
commit 63e30843dc
3 changed files with 19 additions and 8 deletions

View File

@@ -603,10 +603,14 @@ class ErrorFinder(Normalizer):
elif leaf.value in ('yield', 'return'):
if self._context.node.type != 'funcdef':
self._add_syntax_error("'%s' outside function" % leaf.value, leaf.parent)
elif self._context.is_async_funcdef() and leaf.value == 'return' \
and leaf.parent.type == 'return_stmt' \
elif self._context.is_async_funcdef() \
and any(self._context.node.iter_yield_exprs()):
self._add_syntax_error("'return' with value in async generator", leaf.parent)
if leaf.value == 'return' and leaf.parent.type == 'return_stmt':
self._add_syntax_error("'return' with value in async generator", leaf.parent)
elif leaf.value == 'yield' \
and leaf.get_next_leaf() != 'from' \
and self._version == (3, 5):
self._add_syntax_error("'yield' inside async function", leaf.parent)
elif leaf.value == 'await':
if not self._context.is_async_funcdef():
self._add_syntax_error("'await' outside async function", leaf.parent)