diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index d910236..b5702fb 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -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) diff --git a/test/normalizer_issue_files/allowed_syntax_python3.5.py b/test/normalizer_issue_files/allowed_syntax_python3.5.py index f40be8d..cc0385b 100644 --- a/test/normalizer_issue_files/allowed_syntax_python3.5.py +++ b/test/normalizer_issue_files/allowed_syntax_python3.5.py @@ -4,7 +4,6 @@ Mostly allowed syntax in Python 3.5. async def foo(): - yield 1 await bar() #: E901 yield from [] @@ -16,7 +15,6 @@ async def foo(): # With decorator it's a different statement. @bla async def foo(): - yield 1 await bar() #: E901 yield from [] diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 643d02f..a570d1b 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -119,6 +119,7 @@ FAILING_EXAMPLES = [ r'b"\x"', r'b"\"', '*a, *b = 3, 3', + 'async def foo(): yield from []', # Parser/tokenize.c r'"""', @@ -264,6 +265,17 @@ if sys.version_info >= (2, 7): # versions. Just skip it for 2.6. FAILING_EXAMPLES.append('[a, 1] += 3') +if sys.version_info[:2] == (3, 5): + FAILING_EXAMPLES += [ + 'async def foo():\n yield x', + 'async def foo():\n yield x', + ] +else: + FAILING_EXAMPLES += [ + 'async def foo():\n yield x\n return 1', + 'async def foo():\n yield x\n return 1', + ] + def _get_error_list(code, version=None): grammar = parso.load_grammar(version=version) @@ -378,9 +390,6 @@ def test_default_except_error_postition(): # SyntaxError ('async def bla():\n def x(): await bla()', '3.5'), ('yield from []', '3.5'), - ('async def foo(): yield from []', '3.5'), - ('async def foo():\n yield x\n return 1', '3.6'), - ('async def foo():\n yield x\n return 1', '3.6'), ('*a = 3', '3.5'), ('del *a, b', '3.5'), ('def x(*): pass', '3.5'),