mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
Add default 'except:' must be last.
This commit is contained in:
@@ -58,6 +58,16 @@ class ErrorFinder(Normalizer):
|
||||
else:
|
||||
self._add_syntax_error("invalid syntax", leaf)
|
||||
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):
|
||||
if len(self._context.blocks) == _MAX_BLOCK_SIZE:
|
||||
self._add_syntax_error("too many statically nested blocks", node)
|
||||
|
||||
@@ -14,3 +14,19 @@ for x in [1]:
|
||||
for x in [1]:
|
||||
break
|
||||
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',
|
||||
'break',
|
||||
'return',
|
||||
'try: pass\nexcept: pass\nexcept X: pass',
|
||||
|
||||
# IndentationError
|
||||
' foo',
|
||||
|
||||
Reference in New Issue
Block a user