From 99d35e57b68fa6e0a95ec0b2398a24079362ad1f Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 19 Sep 2014 13:42:47 +0200 Subject: [PATCH] Fix alias usages in goto_assignments. --- jedi/evaluate/__init__.py | 2 ++ test/test_api/test_api_classes.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 639d755c..ca01d8af 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -324,6 +324,8 @@ class Evaluator(object): return [call_path[0]] names = stmt.get_all_import_names() + if stmt.alias_name_part: + names = names[:-1] # Filter names that are after our Name removed_names = len(names) - names.index(call_path[0]) - 1 i = imports.ImportWrapper(self, stmt, kill_count=removed_names, diff --git a/test/test_api/test_api_classes.py b/test/test_api/test_api_classes.py index b0e99253..f327113c 100644 --- a/test/test_api/test_api_classes.py +++ b/test/test_api/test_api_classes.py @@ -286,3 +286,15 @@ class TestGotoAssignments(TestCase): n = nms[1].goto_assignments()[0] assert n.name == 'path' assert n.type == 'import' + + def test_import_alias(self): + nms = names('import json as foo', references=True) + assert nms[0].name == 'json' + assert nms[0].type == 'import' + n = nms[0].goto_assignments()[0] + assert n.name == 'json' + assert n.type == 'module' + + assert nms[1].name == 'foo' + assert nms[1].type == 'import' + assert [nms[1]] == nms[1].goto_assignments()