mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 05:34:51 +08:00
Add 'continue' not properly in loop
This commit is contained in:
@@ -85,12 +85,19 @@ class ErrorFinder(Normalizer):
|
||||
else:
|
||||
self._add_syntax_error('invalid syntax', leaf)
|
||||
elif leaf.value == 'continue':
|
||||
in_loop = False
|
||||
for block in self._context.blocks:
|
||||
if block.type == 'for_stmt':
|
||||
in_loop = True
|
||||
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)
|
||||
if not in_loop:
|
||||
message = "'continue' not properly in loop"
|
||||
self._add_syntax_error(message, leaf)
|
||||
return ''
|
||||
|
||||
def _add_indentation_error(self, message, spacing):
|
||||
self._add_error(903, "IndentationError: " + message, spacing)
|
||||
|
||||
@@ -367,6 +367,8 @@ class PEP8Normalizer(ErrorFinder):
|
||||
|
||||
self._previous_leaf = leaf
|
||||
|
||||
return leaf.value
|
||||
|
||||
def _visit_part(self, part, spacing, leaf):
|
||||
value = part.value
|
||||
type_ = part.type
|
||||
|
||||
@@ -9,3 +9,8 @@ for x in [1]:
|
||||
finally:
|
||||
#: E901
|
||||
continue
|
||||
|
||||
|
||||
for x in [1]:
|
||||
break
|
||||
continue
|
||||
|
||||
@@ -67,6 +67,7 @@ def test_indentation_errors(code, positions):
|
||||
finally:
|
||||
continue
|
||||
'''), # 'continue' not supported inside 'finally' clause"
|
||||
'continue'
|
||||
|
||||
# IndentationError
|
||||
' foo',
|
||||
|
||||
Reference in New Issue
Block a user