diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index ea99e550..c52a9d2d 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -350,7 +350,12 @@ class Parser(object): while True: if newline.value == '': # Must be a DEDENT, just continue. - newline = newline.get_previous() + try: + newline = newline.get_previous() + except IndexError: + # If there's a statement that fails to be parsed, there + # will be no previous leaf. So just ignore it. + break elif newline.value != '\n': # This may happen if error correction strikes and removes # a whole statement including '\n'.