Add 'continue' not properly in loop

This commit is contained in:
Dave Halter
2017-07-19 23:52:41 +02:00
parent 4f7d78716a
commit 4a86571b21
4 changed files with 15 additions and 0 deletions

View File

@@ -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)