mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-15 17:07:13 +08:00
Add yield issues when outside function.
This commit is contained in:
@@ -125,9 +125,9 @@ class ErrorFinder(Normalizer):
|
|||||||
in_loop = True
|
in_loop = True
|
||||||
if not in_loop:
|
if not in_loop:
|
||||||
self._add_syntax_error("'break' outside loop", leaf)
|
self._add_syntax_error("'break' outside loop", leaf)
|
||||||
elif leaf.value == 'return':
|
elif leaf.value in ('yield', 'return'):
|
||||||
if self._context.node.type != 'funcdef':
|
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':
|
elif leaf.value == 'await':
|
||||||
if self._context.node.type != 'funcdef' \
|
if self._context.node.type != 'funcdef' \
|
||||||
or self._context.node.parent.type != 'async_funcdef':
|
or self._context.node.parent.type != 'async_funcdef':
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ def test_indentation_errors(code, positions):
|
|||||||
'continue',
|
'continue',
|
||||||
'break',
|
'break',
|
||||||
'return',
|
'return',
|
||||||
|
'yield',
|
||||||
'try: pass\nexcept: pass\nexcept X: pass',
|
'try: pass\nexcept: pass\nexcept X: pass',
|
||||||
|
|
||||||
# IndentationError
|
# IndentationError
|
||||||
@@ -95,6 +96,7 @@ def test_python_exception_matches(code):
|
|||||||
('code', 'version'), [
|
('code', 'version'), [
|
||||||
# SyntaxError
|
# SyntaxError
|
||||||
('async def bla():\n def x(): await bla()', '3.5'),
|
('async def bla():\n def x(): await bla()', '3.5'),
|
||||||
|
('yield from', '3.5'),
|
||||||
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user