From d359f5d0432c52277373247da32f93f3c024da8b Mon Sep 17 00:00:00 2001 From: Pawel Palucki Date: Sat, 26 Jul 2014 22:14:28 +0200 Subject: [PATCH] Sphinx oneline param type declaration feature allows for type definition in ":param keyword" --- docs/docs/features.rst | 3 ++- jedi/evaluate/docstrings.py | 3 +++ test/completion/docstring.py | 12 +++++++++--- test/test_evaluate/test_docstring.py | 10 ++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/docs/features.rst b/docs/docs/features.rst index 321cbf71..f921e13a 100644 --- a/docs/docs/features.rst +++ b/docs/docs/features.rst @@ -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 diff --git a/jedi/evaluate/docstrings.py b/jedi/evaluate/docstrings.py index 9a789a5d..bb882667 100644 --- a/jedi/evaluate/docstrings.py +++ b/jedi/evaluate/docstrings.py @@ -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 diff --git a/test/completion/docstring.py b/test/completion/docstring.py index 1d7bff7f..f80fea31 100644 --- a/test/completion/docstring.py +++ b/test/completion/docstring.py @@ -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() diff --git a/test/test_evaluate/test_docstring.py b/test/test_evaluate/test_docstring.py index daa2d331..59b023a0 100644 --- a/test/test_evaluate/test_docstring.py +++ b/test/test_evaluate/test_docstring.py @@ -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):