documentation to docstring, #395

This commit is contained in:
Dave Halter
2014-04-17 14:13:47 +02:00
parent 2384556861
commit 0582979db5
2 changed files with 22 additions and 23 deletions

View File

@@ -204,7 +204,7 @@ class BaseDefinition(object):
return None return None
return self._start_pos[1] return self._start_pos[1]
def documentation(self): def docstring(self, raw=False):
r""" r"""
Return a document string for this completion object. Return a document string for this completion object.
@@ -216,7 +216,7 @@ class BaseDefinition(object):
... "Document for function f." ... "Document for function f."
... ''' ... '''
>>> script = Script(source, 1, len('def f'), 'example.py') >>> script = Script(source, 1, len('def f'), 'example.py')
>>> doc = script.goto_definitions()[0].documentation() >>> doc = script.goto_definitions()[0].docstring()
>>> print(doc) >>> print(doc)
f(a, b = 1) f(a, b = 1)
<BLANKLINE> <BLANKLINE>
@@ -224,35 +224,36 @@ class BaseDefinition(object):
Notice that useful extra information is added to the actual Notice that useful extra information is added to the actual
docstring. For function, it is call signature. If you need docstring. For function, it is call signature. If you need
actual docstring, use :attr:`raw` instead. actual docstring, use ``raw=True`` instead.
>>> print(doc.raw()) >>> print(script.goto_definitions()[0].docstring(raw=True))
Document for function f. Document for function f.
""" """
return Help(self._definition) if raw:
return Help(self._definition).raw()
else:
return Help(self._definition).full()
@property @property
def doc(self): def doc(self):
""" """
.. deprecated:: 0.8.0 .. deprecated:: 0.8.0
Use :meth:`.documentation` instead. Use :meth:`.docstring` instead.
.. todo:: Remove! .. todo:: Remove!
""" """
warnings.warn("Use documentation() instead.", DeprecationWarning) warnings.warn("Use documentation() instead.", DeprecationWarning)
return self.documentation() return self.docstring()
@property @property
def raw_doc(self): def raw_doc(self):
""" """
.. deprecated:: 0.8.0 .. deprecated:: 0.8.0
Use :meth:`.documentation` instead. Use :meth:`.docstring` instead.
.. todo:: Remove! .. todo:: Remove!
""" """
try: warnings.warn("Use documentation() instead.", DeprecationWarning)
return self._definition.raw_doc return self.docstring(raw=True)
except AttributeError:
return ''
@property @property
def description(self): def description(self):
@@ -451,7 +452,7 @@ 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): def docstring(self, raw=False, fast=True):
""" """
:param fast: Don't follow imports that are only one level deep like :param fast: Don't follow imports that are only one level deep like
``import foo``, but follow ``from foo import bar``. This makes ``import foo``, but follow ``from foo import bar``. This makes
@@ -467,7 +468,11 @@ class Completion(BaseDefinition):
if followed: if followed:
# TODO: Use all of the followed objects as input to Documentation. # TODO: Use all of the followed objects as input to Documentation.
definition = followed[0] definition = followed[0]
return Help(definition)
if raw:
return Help(definition).raw()
else:
return Help(definition).full()
@property @property
def type(self): def type(self):
@@ -712,12 +717,6 @@ class Help(object):
def __init__(self, definition): def __init__(self, definition):
self._definition = definition self._definition = definition
def __str__(self):
return self.full()
def __unicode__(self):
return self.full()
def full(self): def full(self):
try: try:
return self._definition.doc return self._definition.doc

View File

@@ -116,15 +116,15 @@ def test_position_none_if_builtin():
@cwd_at('.') @cwd_at('.')
def test_completion_documentation(): def test_completion_docstring():
""" """
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)) == cleandoc(jedi_doc) assert c.docstring(fast=False) == cleandoc(jedi_doc)
c = Script('import jedi\njedi.Scr').completions()[0] c = Script('import jedi\njedi.Scr').completions()[0]
assert c.documentation(fast=False).raw() == cleandoc(Script.__doc__) assert c.docstring(raw=True, fast=False) == cleandoc(Script.__doc__)
def test_signature_params(): def test_signature_params():