From cfe54e83ffe4bd4d9d86aa37d4940b2e429499c3 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 28 Jul 2014 17:41:09 +0200 Subject: [PATCH] incomplete functions shouldn't cause any trouble. fixes #429. --- jedi/parser/__init__.py | 5 +++-- test/test_parser/test_fast_parser.py | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index e0252e2b..8c7ca567 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -555,8 +555,9 @@ class Parser(object): elif tok_str in ('return', 'yield'): s = tok.start_pos self.freshscope = False - # add returns to the scope - func = self._scope.get_parent_until(pr.Function) + # Add returns to the scope + # Should be a function, otherwise just add it to a module! + func = self._scope.get_parent_until((pr.Function, pr.Module)) if tok_str == 'yield': func.is_generator = True diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index e7883cfa..76fa7f74 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -78,3 +78,10 @@ def test_change_and_undo(): fp('a') fp('b') fp('a') + + +def test_incomplete_function(): + source = '''return ImportErr''' + + script = jedi.Script(dedent(source), 1, 3) + assert script.completions()