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():