1
0
forked from VimPlug/jedi

Add py__doc__ as a better approach to docstrings.

This commit is contained in:
Dave Halter
2017-04-20 09:45:12 +02:00
parent b4631d6dd4
commit 7ca62578e1
6 changed files with 56 additions and 38 deletions

View File

@@ -94,8 +94,7 @@ class CompiledObject(Context):
def is_class(self):
return inspect.isclass(self.obj)
@property
def doc(self):
def py__doc__(self, include_call_signature=False):
return inspect.getdoc(self.obj) or ''
@property
@@ -129,10 +128,11 @@ class CompiledObject(Context):
@underscore_memoization
def _parse_function_doc(self):
if self.doc is None:
doc = self.py__doc__()
if doc is None:
return '', ''
return _parse_function_doc(self.doc)
return _parse_function_doc(doc)
@property
def api_type(self):

View File

@@ -1,6 +1,7 @@
from jedi._compatibility import Python3Method
from jedi.common import unite
from jedi.parser.python.tree import ExprStmt, CompFor
from jedi.parser_utils import clean_scope_docstring, get_doc_with_call_signature
class Context(object):
@@ -63,6 +64,18 @@ class Context(object):
"""
return True
def py__doc__(self, include_call_signature=False):
try:
self.tree_node.get_doc_node
except AttributeError:
return ''
else:
if include_call_signature:
return get_doc_with_call_signature(self.tree_node)
else:
return clean_scope_docstring(self.tree_node)
return None
class TreeContext(Context):
def __init__(self, evaluator, parent_context=None):

View File

@@ -32,6 +32,8 @@ py__package__() Only on modules. For the import system.
py__path__() Only on modules. For the import system.
py__get__(call_object) Only on instances. Simulates
descriptors.
py__doc__(include_call_signature: Returns the docstring for a context.
bool)
====================================== ========================================
"""