Skip to content

Commit

Permalink
missing docstrings for imports in completions should be there now, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Mar 25, 2014
1 parent 33d59d8 commit 4a9b938
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
24 changes: 21 additions & 3 deletions jedi/api/classes.py
Expand Up @@ -347,7 +347,7 @@ def complete(self):
@property
def name(self):
"""
Similar to :meth:`Completion.complete`, but return the whole word, for
Similar to :attr:`complete`, but return the whole word, for
example::
isinstan
Expand All @@ -359,7 +359,7 @@ def name(self):
@property
def name_with_symbols(self):
"""
Similar to :meth:`Completion.name`, but like :meth:`Completion.name`
Similar to :attr:`name`, but like :attr:`name`
returns also the symbols, for example::
list()
Expand Down Expand Up @@ -396,6 +396,24 @@ def description(self):
def __repr__(self):
return '<%s: %s>' % (type(self).__name__, self._name)

def documentation(self, fast=True):
"""
:param fast: Don't follow imports that are only one level deep like
``import foo``, but follow ``from foo import bar``. This makes
sense for speed reasons. Completing `import a` is slow if you use
the ``foo.documentation(fast=False)`` on every object, because it
parses all libraries starting with ``a``.
"""
definition = self._definition
if isinstance(self._definition, pr.Import):
i = imports.ImportPath(self._evaluator, self._definition)
if len(i.import_path) > 1 or not fast:
followed = self.follow_definition()
if followed:
# TODO: Use all of the followed objects as input to Documentation.
definition = followed[0]._definition
return Documentation(definition)

@property
def type(self):
"""
Expand Down Expand Up @@ -653,7 +671,7 @@ def __str__(self):
try:
return self._definition.doc
except AttributeError:
return self.raw_doc
return self.raw()

def raw(self):
"""
Expand Down
5 changes: 3 additions & 2 deletions test/test_api/test_api_classes.py
Expand Up @@ -2,6 +2,7 @@
"""

import textwrap
from inspect import cleandoc

import pytest

Expand Down Expand Up @@ -118,7 +119,7 @@ def test_completion_documentation():
Jedi should follow imports in certain conditions
"""
c = Script('import jedi\njed').completions()[0]
assert str(c.documentation(fast=False)) == jedi_doc
assert str(c.documentation(fast=False)) == cleandoc(jedi_doc)

c = Script('import jedi\njedi.Scr').completions()[0]
assert str(c.documentation(fast=False)) == Script.__doc__
assert c.documentation(fast=False).raw() == cleandoc(Script.__doc__)

0 comments on commit 4a9b938

Please sign in to comment.