mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Sphinx oneline param type declaration feature
allows for type definition in ":param keyword"
This commit is contained in:
@@ -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``.
|
||||
|
||||
:type node: ProgramNode
|
||||
:param str foo: foo parameter description
|
||||
|
||||
"""
|
||||
node.| # complete here
|
||||
|
||||
@@ -24,6 +24,7 @@ from jedi.common import indent_block
|
||||
|
||||
DOCSTRING_PARAM_PATTERNS = [
|
||||
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
|
||||
]
|
||||
|
||||
@@ -55,6 +56,8 @@ def _search_param_in_docstr(docstr, param_str):
|
||||
'threading.Thread'
|
||||
>>> _search_param_in_docstr('no document', 'param') is None
|
||||
True
|
||||
>>> _search_param_in_docstr(':param int param: some description', 'param')
|
||||
'int'
|
||||
|
||||
"""
|
||||
# look at #40 to see definitions of those params
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
# -----------------
|
||||
# sphinx style
|
||||
# -----------------
|
||||
def f(a, b, c, d):
|
||||
def f(a, b, c, d, x):
|
||||
""" asdfasdf
|
||||
:param a: blablabla
|
||||
:type a: str
|
||||
:type b: (str, int)
|
||||
:type c: threading.Thread
|
||||
:type d: :class:`threading.Thread`
|
||||
:param str x: blablabla
|
||||
:rtype: dict
|
||||
"""
|
||||
#? str()
|
||||
@@ -22,23 +23,28 @@ def f(a, b, c, d):
|
||||
c.join
|
||||
#? ['join']
|
||||
d.join
|
||||
#? ['lower']
|
||||
x.lower
|
||||
|
||||
#? dict()
|
||||
f()
|
||||
|
||||
# wrong declarations
|
||||
def f(a, b):
|
||||
def f(a, b, x):
|
||||
"""
|
||||
:param a: Forgot type declaration
|
||||
:type a:
|
||||
:param b: Just something
|
||||
:type b: ``
|
||||
:rtype:
|
||||
:param x: Just something without type
|
||||
:rtype:
|
||||
"""
|
||||
#?
|
||||
a
|
||||
#?
|
||||
b
|
||||
#?
|
||||
x
|
||||
|
||||
#?
|
||||
f()
|
||||
|
||||
@@ -50,6 +50,16 @@ class TestDocstring(unittest.TestCase):
|
||||
names = [c.name for c in jedi.Script(s).completions()]
|
||||
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):
|
||||
s = """
|
||||
def func(arg):
|
||||
|
||||
Reference in New Issue
Block a user