mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-22 13:21:26 +08:00
missing docstrings for imports in completions should be there now, fixes #340
This commit is contained in:
@@ -347,7 +347,7 @@ class Completion(BaseDefinition):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
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::
|
example::
|
||||||
|
|
||||||
isinstan
|
isinstan
|
||||||
@@ -359,7 +359,7 @@ class Completion(BaseDefinition):
|
|||||||
@property
|
@property
|
||||||
def name_with_symbols(self):
|
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::
|
returns also the symbols, for example::
|
||||||
|
|
||||||
list()
|
list()
|
||||||
@@ -396,6 +396,24 @@ class Completion(BaseDefinition):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self._name)
|
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
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
"""
|
"""
|
||||||
@@ -653,7 +671,7 @@ class Documentation(object):
|
|||||||
try:
|
try:
|
||||||
return self._definition.doc
|
return self._definition.doc
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return self.raw_doc
|
return self.raw()
|
||||||
|
|
||||||
def raw(self):
|
def raw(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from inspect import cleandoc
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -118,7 +119,7 @@ def test_completion_documentation():
|
|||||||
Jedi should follow imports in certain conditions
|
Jedi should follow imports in certain conditions
|
||||||
"""
|
"""
|
||||||
c = Script('import jedi\njed').completions()[0]
|
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]
|
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__)
|
||||||
|
|||||||
Reference in New Issue
Block a user