mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-25 05:06:42 +08:00
Merge branch 'add-numpydoc-support' of git://github.com/immerrr/jedi into dev
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -6,6 +6,13 @@ from textwrap import dedent
|
||||
import jedi
|
||||
from ..helpers import unittest
|
||||
|
||||
try:
|
||||
import numpydoc
|
||||
except ImportError:
|
||||
numpydoc_unavailable = True
|
||||
else:
|
||||
numpydoc_unavailable = False
|
||||
|
||||
|
||||
class TestDocstring(unittest.TestCase):
|
||||
def test_function_doc(self):
|
||||
@@ -50,6 +57,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):
|
||||
@@ -87,3 +104,49 @@ class TestDocstring(unittest.TestCase):
|
||||
assert 'a' in names
|
||||
assert '__init__' in names
|
||||
assert 'mro' not in names # Exists only for types.
|
||||
|
||||
@unittest.skipIf(numpydoc_unavailable, 'numpydoc module is unavailable')
|
||||
def test_numpydoc_docstring(self):
|
||||
s = dedent('''
|
||||
def foobar(x, y):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
x : int
|
||||
y : str
|
||||
"""
|
||||
y.''')
|
||||
names = [c.name for c in jedi.Script(s).completions()]
|
||||
assert 'isupper' in names
|
||||
assert 'capitalize' in names
|
||||
|
||||
@unittest.skipIf(numpydoc_unavailable, 'numpydoc module is unavailable')
|
||||
def test_numpydoc_docstring_set_of_values(self):
|
||||
s = dedent('''
|
||||
def foobar(x, y):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
x : {'foo', 'bar', 100500}, optional
|
||||
"""
|
||||
x.''')
|
||||
names = [c.name for c in jedi.Script(s).completions()]
|
||||
assert 'isupper' in names
|
||||
assert 'capitalize' in names
|
||||
assert 'numerator' in names
|
||||
|
||||
@unittest.skipIf(numpydoc_unavailable, 'numpydoc module is unavailable')
|
||||
def test_numpydoc_alternative_types(self):
|
||||
s = dedent('''
|
||||
def foobar(x, y):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
x : int or str or list
|
||||
"""
|
||||
x.''')
|
||||
names = [c.name for c in jedi.Script(s).completions()]
|
||||
assert 'isupper' in names
|
||||
assert 'capitalize' in names
|
||||
assert 'numerator' in names
|
||||
assert 'append' in names
|
||||
|
||||
Reference in New Issue
Block a user