mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-15 00:47:11 +08:00
await checks.
This commit is contained in:
@@ -128,6 +128,10 @@ class ErrorFinder(Normalizer):
|
|||||||
elif leaf.value == 'return':
|
elif leaf.value == '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("'return' outside function", leaf)
|
||||||
|
elif leaf.value == 'await':
|
||||||
|
if self._context.node.type != 'funcdef' \
|
||||||
|
or self._context.node.parent.type != 'async_funcdef':
|
||||||
|
self._add_syntax_error("'await' outside async function", leaf)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def _add_indentation_error(self, message, spacing):
|
def _add_indentation_error(self, message, spacing):
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ Some syntax errors are a bit complicated and need exact checking. Here we
|
|||||||
gather some of the potentially dangerous ones.
|
gather some of the potentially dangerous ones.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
for x in [1]:
|
for x in [1]:
|
||||||
try:
|
try:
|
||||||
continue # Only the other continue and pass is an error.
|
continue # Only the other continue and pass is an error.
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
Testing if parso finds syntax errors and indentation errors.
|
Testing if parso finds syntax errors and indentation errors.
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from textwrap import dedent
|
|
||||||
|
|
||||||
import parso
|
import parso
|
||||||
from parso.python.normalizer import ErrorFinderConfig
|
from parso.python.normalizer import ErrorFinderConfig
|
||||||
@@ -90,6 +91,27 @@ def test_python_exception_matches(code):
|
|||||||
assert wanted == error.message
|
assert wanted == error.message
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
('code', 'version'), [
|
||||||
|
# SyntaxError
|
||||||
|
('async def bla():\n def x(): await bla()', '3.5'),
|
||||||
|
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_python_exception_matches_version(code, version):
|
||||||
|
if '.'.join(str(v) for v in sys.version_info[:2]) != version:
|
||||||
|
pytest.skip()
|
||||||
|
|
||||||
|
error, = _get_error_list(code)
|
||||||
|
try:
|
||||||
|
compile(code, '<unknown>', 'exec')
|
||||||
|
except (SyntaxError, IndentationError) as e:
|
||||||
|
wanted = e.__class__.__name__ + ': ' + e.msg
|
||||||
|
else:
|
||||||
|
assert False, "The piece of code should raise an exception."
|
||||||
|
assert wanted == error.message
|
||||||
|
|
||||||
|
|
||||||
def test_statically_nested_blocks():
|
def test_statically_nested_blocks():
|
||||||
def indent(code):
|
def indent(code):
|
||||||
lines = code.splitlines(True)
|
lines = code.splitlines(True)
|
||||||
|
|||||||
Reference in New Issue
Block a user