mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 13:24:39 +08:00
Add 'yield' inside async function' for Python 3.5.
This commit is contained in:
@@ -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()):
|
||||
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)
|
||||
|
||||
@@ -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 []
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user