mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Fix the last IndentationError.
This commit is contained in:
@@ -48,7 +48,12 @@ class ErrorFinder(Normalizer):
|
|||||||
def visit_node(self, node):
|
def visit_node(self, node):
|
||||||
if node.type == 'error_node':
|
if node.type == 'error_node':
|
||||||
leaf = node.get_next_leaf()
|
leaf = node.get_next_leaf()
|
||||||
self._add_syntax_error("invalid syntax", leaf)
|
if node.children[-1].type == 'newline':
|
||||||
|
# This is the beginning of a suite that is not indented.
|
||||||
|
spacing = list(leaf._split_prefix())[-1]
|
||||||
|
self._add_indentation_error('expected an indented block', spacing)
|
||||||
|
else:
|
||||||
|
self._add_syntax_error("invalid syntax", leaf)
|
||||||
elif node.type in _BLOCK_STMTS:
|
elif node.type in _BLOCK_STMTS:
|
||||||
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:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ True and False
|
|||||||
if 1:
|
if 1:
|
||||||
pass
|
pass
|
||||||
# Syntax Error, no indentation
|
# Syntax Error, no indentation
|
||||||
#: E901+1
|
#: E903+1
|
||||||
if 1:
|
if 1:
|
||||||
pass
|
pass
|
||||||
#: E223:8
|
#: E223:8
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ def test_syntax_errors(code, positions):
|
|||||||
(' 1', [(1, 0)]),
|
(' 1', [(1, 0)]),
|
||||||
('def x():\n 1\n 2', [(3, 0)]),
|
('def x():\n 1\n 2', [(3, 0)]),
|
||||||
('def x():\n 1\n 2', [(3, 0)]),
|
('def x():\n 1\n 2', [(3, 0)]),
|
||||||
|
('def x():\n1', [(2, 0)]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_indentation_errors(code, positions):
|
def test_indentation_errors(code, positions):
|
||||||
@@ -63,6 +64,7 @@ def test_indentation_errors(code, positions):
|
|||||||
' foo',
|
' foo',
|
||||||
'def x():\n 1\n 2',
|
'def x():\n 1\n 2',
|
||||||
'def x():\n 1\n 2',
|
'def x():\n 1\n 2',
|
||||||
|
'if 1:\nfoo',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_python_exception_matches(code):
|
def test_python_exception_matches(code):
|
||||||
|
|||||||
Reference in New Issue
Block a user