diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index ef51298c..da91b531 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -231,7 +231,8 @@ class Script(object): tokenizer = source_tokens(cursor_txt, self._pos[0] - 1) r = Parser(cursor_txt, no_docstr=True, tokenizer=tokenizer) try: - stmt = r.module.statements[0] + # Take the last statement available. + stmt = r.module.statements[-1] except IndexError: raise NotFoundError() # Set the start_pos to a pseudo position, that doesn't exist but works diff --git a/test/completion/invalid.py b/test/completion/invalid.py index d10c08e4..b6c6e1cb 100644 --- a/test/completion/invalid.py +++ b/test/completion/invalid.py @@ -137,8 +137,8 @@ def break(): pass #? int() a[0] -#? [] -int()). +#? ['real'] +int()).real # ----------------- # keywords