From 15fdecdb61dd0d9ca87c159490256b35197e30cb Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 16 Apr 2014 09:57:01 +0200 Subject: [PATCH] for flows triggered an exception if goto_assignments was used on the keyword. found with the help of sith.py --- jedi/api/__init__.py | 3 +++ jedi/parser/representation.py | 12 +++++++----- test/test_api/test_api.py | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index ff774584..4838ff1a 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -266,6 +266,9 @@ class Script(object): stmt = r.module.statements[-1] except IndexError: raise NotFoundError() + if isinstance(stmt, pr.Flow): + raise NotFoundError() + user_stmt = self._parser.user_stmt() if user_stmt is None: # Set the start_pos to a pseudo position, that doesn't exist but works diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 42103727..ca02f5c4 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -679,13 +679,15 @@ class ForFlow(Flow): super(ForFlow, self).__init__(module, 'for', inputs, start_pos) self.set_stmt = set_stmt - set_stmt.parent = self.use_as_parent self.is_list_comp = is_list_comp - self.set_vars = set_stmt.get_defined_names() - for s in self.set_vars: - s.parent.parent = self.use_as_parent - s.parent = self.use_as_parent + if set_stmt is not None: + set_stmt.parent = self.use_as_parent + self.set_vars = set_stmt.get_defined_names() + + for s in self.set_vars: + s.parent.parent = self.use_as_parent + s.parent = self.use_as_parent def get_code(self, first_indent=False, indention=" " * 4): vars = ",".join(x.get_code() for x in self.set_vars) diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index d9f43a73..151738ed 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -94,3 +94,8 @@ def test_completion_on_complex_literals(): _check_number('4.0j.', 'complex') # No dot no completion assert api.Script('4j').completions() == [] + + +def test_goto_assignments_on_for(): + with raises(api.NotFoundError): + api.Script('for').goto_assignments()