From 1bc9ac1c000015c1967ee68e34d3ce9dfb6b803d Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 27 Feb 2015 11:37:49 +0100 Subject: [PATCH] Goto bug fix. --- jedi/api/__init__.py | 6 +++++- test/test_api/test_api.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 3e5fb6c4..cfdfe2fc 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -407,7 +407,11 @@ class Script(object): if last_name is None: last_name = stmt while not isinstance(last_name, pr.Name): - last_name = last_name.children[-1] + try: + last_name = last_name.children[-1] + except AttributeError: + # Doesn't have a name in it. + return [] if next(context) in ('class', 'def'): # The cursor is on a class/function name. diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index 65a6794e..041f5252 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -101,10 +101,11 @@ def test_completion_on_complex_literals(): assert api.Script('4j').completions() == [] -def test_goto_assignments_on_non_statement(): +def test_goto_assignments_on_non_name(): assert api.Script('for').goto_assignments() == [] assert api.Script('assert').goto_assignments() == [] + assert api.Script('True').goto_assignments() == [] def test_goto_definition_not_multiple():