From 26c71a95866211f94430f91811966f5a1b04f2da Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 20 Jul 2017 09:51:35 +0200 Subject: [PATCH] Add yield issues when outside function. --- parso/python/normalizer.py | 4 ++-- test/test_python_errors.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index b7dbe35..64d6c35 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -125,9 +125,9 @@ class ErrorFinder(Normalizer): in_loop = True if not in_loop: self._add_syntax_error("'break' outside loop", leaf) - elif leaf.value == 'return': + elif leaf.value in ('yield', 'return'): if self._context.node.type != 'funcdef': - self._add_syntax_error("'return' outside function", leaf) + self._add_syntax_error("'%s' outside function" % leaf.value, leaf) elif leaf.value == 'await': if self._context.node.type != 'funcdef' \ or self._context.node.parent.type != 'async_funcdef': diff --git a/test/test_python_errors.py b/test/test_python_errors.py index b594448..510f8d5 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -71,6 +71,7 @@ def test_indentation_errors(code, positions): 'continue', 'break', 'return', + 'yield', 'try: pass\nexcept: pass\nexcept X: pass', # IndentationError @@ -95,6 +96,7 @@ def test_python_exception_matches(code): ('code', 'version'), [ # SyntaxError ('async def bla():\n def x(): await bla()', '3.5'), + ('yield from', '3.5'), ] )