Sphinx oneline param type declaration feature

allows for type definition in ":param keyword"
This commit is contained in:
Pawel Palucki
2014-07-26 22:14:28 +02:00
parent 293fa5a14f
commit d359f5d043
4 changed files with 24 additions and 4 deletions

View File

@@ -119,10 +119,11 @@ http://sphinx-doc.org/domains.html#info-field-lists
:: ::
def myfunction(node): def myfunction(node, foo):
"""Do something with a ``node``. """Do something with a ``node``.
:type node: ProgramNode :type node: ProgramNode
:param str foo: foo parameter description
""" """
node.| # complete here node.| # complete here

View File

@@ -24,6 +24,7 @@ from jedi.common import indent_block
DOCSTRING_PARAM_PATTERNS = [ DOCSTRING_PARAM_PATTERNS = [
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
r'\s*:param\s+(\w+)\s+%s:[^\n]+', # Sphinx param with type
r'\s*@type\s+%s:\s*([^\n]+)', # Epydoc r'\s*@type\s+%s:\s*([^\n]+)', # Epydoc
] ]
@@ -55,6 +56,8 @@ def _search_param_in_docstr(docstr, param_str):
'threading.Thread' 'threading.Thread'
>>> _search_param_in_docstr('no document', 'param') is None >>> _search_param_in_docstr('no document', 'param') is None
True True
>>> _search_param_in_docstr(':param int param: some description', 'param')
'int'
""" """
# look at #40 to see definitions of those params # look at #40 to see definitions of those params

View File

@@ -3,13 +3,14 @@
# ----------------- # -----------------
# sphinx style # sphinx style
# ----------------- # -----------------
def f(a, b, c, d): def f(a, b, c, d, x):
""" asdfasdf """ asdfasdf
:param a: blablabla :param a: blablabla
:type a: str :type a: str
:type b: (str, int) :type b: (str, int)
:type c: threading.Thread :type c: threading.Thread
:type d: :class:`threading.Thread` :type d: :class:`threading.Thread`
:param str x: blablabla
:rtype: dict :rtype: dict
""" """
#? str() #? str()
@@ -22,23 +23,28 @@ def f(a, b, c, d):
c.join c.join
#? ['join'] #? ['join']
d.join d.join
#? ['lower']
x.lower
#? dict() #? dict()
f() f()
# wrong declarations # wrong declarations
def f(a, b): def f(a, b, x):
""" """
:param a: Forgot type declaration :param a: Forgot type declaration
:type a: :type a:
:param b: Just something :param b: Just something
:type b: `` :type b: ``
:param x: Just something without type
:rtype: :rtype:
""" """
#? #?
a a
#? #?
b b
#?
x
#? #?
f() f()

View File

@@ -50,6 +50,16 @@ class TestDocstring(unittest.TestCase):
names = [c.name for c in jedi.Script(s).completions()] names = [c.name for c in jedi.Script(s).completions()]
assert 'start' in names assert 'start' in names
def test_docstrings_param_type(self):
s = """
def func(arg):
'''
:param str arg: some description
'''
arg."""
names = [c.name for c in jedi.Script(s).completions()]
assert 'join' in names
def test_docstrings_type_str(self): def test_docstrings_type_str(self):
s = """ s = """
def func(arg): def func(arg):