mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Add default 'except:' must be last.
This commit is contained in:
@@ -58,6 +58,16 @@ class ErrorFinder(Normalizer):
|
|||||||
else:
|
else:
|
||||||
self._add_syntax_error("invalid syntax", leaf)
|
self._add_syntax_error("invalid syntax", leaf)
|
||||||
elif node.type in _BLOCK_STMTS:
|
elif node.type in _BLOCK_STMTS:
|
||||||
|
if node.type == 'try_stmt':
|
||||||
|
default_except = None
|
||||||
|
for except_clause in node.children[3::3]:
|
||||||
|
if except_clause in ('else', 'finally'):
|
||||||
|
break
|
||||||
|
if except_clause == 'except':
|
||||||
|
default_except = except_clause
|
||||||
|
elif default_except is not None:
|
||||||
|
self._add_syntax_error("default 'except:' must be last", default_except)
|
||||||
|
|
||||||
with self._context.add_block(node):
|
with self._context.add_block(node):
|
||||||
if len(self._context.blocks) == _MAX_BLOCK_SIZE:
|
if len(self._context.blocks) == _MAX_BLOCK_SIZE:
|
||||||
self._add_syntax_error("too many statically nested blocks", node)
|
self._add_syntax_error("too many statically nested blocks", node)
|
||||||
|
|||||||
@@ -14,3 +14,19 @@ for x in [1]:
|
|||||||
for x in [1]:
|
for x in [1]:
|
||||||
break
|
break
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
pass
|
||||||
|
except ZeroDivisionError:
|
||||||
|
pass
|
||||||
|
#: E722:0
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
pass
|
||||||
|
#: E722:0 E901:0
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
except ZeroDivisionError:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ def test_indentation_errors(code, positions):
|
|||||||
'continue',
|
'continue',
|
||||||
'break',
|
'break',
|
||||||
'return',
|
'return',
|
||||||
|
'try: pass\nexcept: pass\nexcept X: pass',
|
||||||
|
|
||||||
# IndentationError
|
# IndentationError
|
||||||
' foo',
|
' foo',
|
||||||
|
|||||||
Reference in New Issue
Block a user