mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-09 22:25:53 +08:00
Add 'continue' not supported inside 'finally' clause.
This commit is contained in:
@@ -76,7 +76,6 @@ class ErrorFinder(Normalizer):
|
|||||||
# Indents/Dedents itself never have a prefix. They are just
|
# Indents/Dedents itself never have a prefix. They are just
|
||||||
# "pseudo" tokens that get removed by the syntax tree later.
|
# "pseudo" tokens that get removed by the syntax tree later.
|
||||||
# Therefore in case of an error we also have to check for this.
|
# Therefore in case of an error we also have to check for this.
|
||||||
print(repr(leaf.prefix), leaf.get_next_leaf())
|
|
||||||
spacing = list(leaf.get_next_leaf()._split_prefix())[-1]
|
spacing = list(leaf.get_next_leaf()._split_prefix())[-1]
|
||||||
if leaf.original_type == 'indent':
|
if leaf.original_type == 'indent':
|
||||||
message = 'unexpected indent'
|
message = 'unexpected indent'
|
||||||
@@ -85,6 +84,13 @@ class ErrorFinder(Normalizer):
|
|||||||
self._add_indentation_error(message, spacing)
|
self._add_indentation_error(message, spacing)
|
||||||
else:
|
else:
|
||||||
self._add_syntax_error('invalid syntax', leaf)
|
self._add_syntax_error('invalid syntax', leaf)
|
||||||
|
elif leaf.value == 'continue':
|
||||||
|
for block in self._context.blocks:
|
||||||
|
if block.type == 'try_stmt':
|
||||||
|
last_block = block.children[-3]
|
||||||
|
if last_block == 'finally' and leaf.start_pos > last_block.start_pos:
|
||||||
|
message = "'continue' not supported inside 'finally' clause"
|
||||||
|
self._add_syntax_error(message, leaf)
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|||||||
@@ -174,8 +174,10 @@ class PEP8Normalizer(ErrorFinder):
|
|||||||
@contextmanager
|
@contextmanager
|
||||||
def visit_node(self, node):
|
def visit_node(self, node):
|
||||||
with super(PEP8Normalizer, self).visit_node(node):
|
with super(PEP8Normalizer, self).visit_node(node):
|
||||||
return self._visit_node(node)
|
with self._visit_node(node):
|
||||||
|
yield
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
def _visit_node(self, node):
|
def _visit_node(self, node):
|
||||||
typ = node.type
|
typ = node.type
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Testing if parso finds syntax errors and indentation errors.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import ast
|
from textwrap import dedent
|
||||||
|
|
||||||
import parso
|
import parso
|
||||||
from parso.python.normalizer import ErrorFinderConfig
|
from parso.python.normalizer import ErrorFinderConfig
|
||||||
@@ -60,6 +60,14 @@ def test_indentation_errors(code, positions):
|
|||||||
# SyntaxError
|
# SyntaxError
|
||||||
'1 +',
|
'1 +',
|
||||||
'?',
|
'?',
|
||||||
|
dedent('''\
|
||||||
|
for a in [1]:
|
||||||
|
try:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
continue
|
||||||
|
'''), # 'continue' not supported inside 'finally' clause"
|
||||||
|
|
||||||
# IndentationError
|
# IndentationError
|
||||||
' foo',
|
' foo',
|
||||||
'def x():\n 1\n 2',
|
'def x():\n 1\n 2',
|
||||||
@@ -70,7 +78,7 @@ def test_indentation_errors(code, positions):
|
|||||||
def test_python_exception_matches(code):
|
def test_python_exception_matches(code):
|
||||||
error, = _get_error_list(code)
|
error, = _get_error_list(code)
|
||||||
try:
|
try:
|
||||||
ast.parse(code)
|
compile(code, '<unknown>', 'exec')
|
||||||
except (SyntaxError, IndentationError) as e:
|
except (SyntaxError, IndentationError) as e:
|
||||||
wanted = e.__class__.__name__ + ': ' + e.msg
|
wanted = e.__class__.__name__ + ': ' + e.msg
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user