mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +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``.
|
"""Do something with a ``node``.
|
||||||
|
|
||||||
:type node: ProgramNode
|
:type node: ProgramNode
|
||||||
|
:param str foo: foo parameter description
|
||||||
|
|
||||||
"""
|
"""
|
||||||
node.| # complete here
|
node.| # complete here
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user