mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-25 01:38:52 +08:00
Move the TryStmtRule.
This commit is contained in:
+15
-10
@@ -294,16 +294,6 @@ class ErrorFinder(Normalizer):
|
|||||||
# Error leafs will be added later as an error.
|
# Error leafs will be added later as an error.
|
||||||
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)
|
||||||
@@ -808,6 +798,21 @@ class _ParameterRule(SyntaxRule):
|
|||||||
default_only = True
|
default_only = True
|
||||||
|
|
||||||
|
|
||||||
|
@ErrorFinder.register_rule(type='try_stmt')
|
||||||
|
class _TryStmtRule(SyntaxRule):
|
||||||
|
message = "default 'except:' must be last"
|
||||||
|
|
||||||
|
def is_issue(self, try_stmt):
|
||||||
|
default_except = None
|
||||||
|
for except_clause in try_stmt.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_issue(default_except, message=self.message)
|
||||||
|
|
||||||
|
|
||||||
class _CheckAssignmentRule(SyntaxRule):
|
class _CheckAssignmentRule(SyntaxRule):
|
||||||
def _check_assignment(self, node, is_deletion=False):
|
def _check_assignment(self, node, is_deletion=False):
|
||||||
error = None
|
error = None
|
||||||
|
|||||||
Reference in New Issue
Block a user