From 5280f567f90ac4fc1942444bcedc34befaba49b6 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 9 Jul 2016 01:04:15 +0200 Subject: [PATCH] The docstring of import completions was wrong. This is fixed now. However, since this might massively decrease performance, it's not enabled by default. You can enable it with `docstring(fast=False)` (see test changes), but I wouldn't recommend it at this point. Fixes #656. --- jedi/evaluate/imports.py | 6 +++++- test/test_evaluate/test_imports.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 7c26280a..1cbdaf92 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -355,7 +355,11 @@ class Importer(object): return set([module]) def _generate_name(self, name): - return helpers.FakeName(name, parent=self.module) + # Create a pseudo import to be able to follow them. + name = helpers.FakeName(name) + imp = helpers.FakeImport(name, parent=self.module) + name.parent = imp + return name def _get_module_names(self, search_path=None): """ diff --git a/test/test_evaluate/test_imports.py b/test/test_evaluate/test_imports.py index 0bff5a70..98c8baf2 100644 --- a/test/test_evaluate/test_imports.py +++ b/test/test_evaluate/test_imports.py @@ -77,3 +77,15 @@ def test_cache_works_with_sys_path_param(tmpdir): assert 'bar' in [c.name for c in bar_completions] assert 'foo' not in [c.name for c in bar_completions] + + +def test_import_completion_docstring(): + import abc + s = jedi.Script('"""test"""\nimport ab') + completions = s.completions() + assert len(completions) == 1 + assert completions[0].docstring(fast=False) == abc.__doc__ + + # However for performance reasons not all modules are loaded and the + # docstring is empty in this case. + assert completions[0].docstring() == ''