diff options
author | Ashley Whetter <ashley@awhetter.co.uk> | 2016-06-25 20:50:29 +0100 |
---|---|---|
committer | Ashley Whetter <ashley@awhetter.co.uk> | 2016-06-25 20:50:29 +0100 |
commit | deaedd4309309d2e53cdef2362896dddda780a1f (patch) | |
tree | f1d0e484f8314dcbe7a27eaf6bf27927f3aeda05 /pylint | |
parent | b4b6fd1181377b3c99e78ace2dad51d5ed08667b (diff) | |
download | pylint-git-deaedd4309309d2e53cdef2362896dddda780a1f.tar.gz |
Fixed qualified type detection in sphinx docstrings
Fixes #949
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/extensions/_check_docs_utils.py | 26 | ||||
-rw-r--r-- | pylint/test/extensions/test_check_docs.py | 19 |
2 files changed, 27 insertions, 18 deletions
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index 3d91d963b..70054e9ab 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -110,41 +110,48 @@ class Docstring(object): return self.re_for_parameters_see.search(self.doc) is not None class SphinxDocstring(Docstring): + re_type = r"[\w\.]+" + + re_xref = r""" + (?::\w+:)? # optional tag + `{0}` # what to reference + """.format(re_type) + re_param_in_docstring = re.compile(r""" :param # Sphinx keyword \s+ # whitespace (?: # optional type declaration - (\w+) + ({type}) \s+ )? (\w+) # Parameter name \s* # whitespace : # final colon - """, re.X | re.S) + """.format(type=re_type, xref=re_xref), re.X | re.S) re_type_in_docstring = re.compile(r""" :type # Sphinx keyword \s+ # whitespace - (\w+) # Parameter name + ({type}) # Parameter name \s* # whitespace : # final colon - """, re.X | re.S) + """.format(type=re_type, xref=re_xref), re.X | re.S) re_raise_in_docstring = re.compile(r""" :raises # Sphinx keyword \s+ # whitespace (?: # type declaration - (\w+) + ({type}) \s+ )? (\w+) # Parameter name \s* # whitespace : # final colon - """, re.X | re.S) + """.format(type=re_type, xref=re_xref), re.X | re.S) re_rtype_in_docstring = re.compile(r":rtype:") @@ -194,12 +201,9 @@ class SphinxDocstring(Docstring): class GoogleDocstring(Docstring): - re_type = r"[\w_\.]+" + re_type = SphinxDocstring.re_type - re_xref = r""" - (?::\w+:)? # optional tag - `{0}` # what to reference - """.format(re_type) + re_xref = SphinxDocstring.re_xref re_container_type = r""" (?:{type}|{xref}) # a container type diff --git a/pylint/test/extensions/test_check_docs.py b/pylint/test/extensions/test_check_docs.py index 19250b496..31a3e75cf 100644 --- a/pylint/test/extensions/test_check_docs.py +++ b/pylint/test/extensions/test_check_docs.py @@ -249,17 +249,19 @@ class ParamDocCheckerTest(CheckerTestCase): return values (Sphinx style) """ node = test_utils.extract_node(""" - def function_foo(xarg, yarg, zarg): + def function_foo(xarg, yarg, zarg, warg): '''function foo ... :param xarg: bla xarg :type xarg: int :param yarg: bla yarg - :type yarg: float + :type yarg: my.qualified.type :param int zarg: bla zarg + :param my.qualified.type warg: bla warg + :return: sum :rtype: float ''' @@ -273,15 +275,16 @@ class ParamDocCheckerTest(CheckerTestCase): return values (Google style) """ node = test_utils.extract_node(""" - def function_foo(xarg, yarg, zarg): + def function_foo(xarg, yarg, zarg, warg): '''function foo ... Args: xarg (int): bla xarg - yarg (float): bla + yarg (my.qualified.type): bla bla yarg - + zarg (int): bla zarg + warg (my.qualified.type): bla warg Returns: float: sum @@ -296,18 +299,20 @@ class ParamDocCheckerTest(CheckerTestCase): return values (Numpy style) """ node = test_utils.extract_node(""" - def function_foo(xarg, yarg, zarg): + def function_foo(xarg, yarg, zarg, warg): '''function foo ... Parameters ---------- xarg: int bla xarg - yarg: float + yarg: my.qualified.type bla yarg zarg: int bla zarg + warg: my.qualified.type + bla warg Returns ------- |