summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Whetter <ashley@awhetter.co.uk>2016-06-25 20:50:29 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2016-07-07 15:24:36 +0100
commitb4602c599fcf4f7291c3de0c5b1e10ee117c0507 (patch)
treeb223396669068d58e12af6ae6c6faba6499e1e67
parentf6e7a83ebcc5e1904a0bbfcbe7e5da00dfd79ffd (diff)
downloadpylint-git-b4602c599fcf4f7291c3de0c5b1e10ee117c0507.tar.gz
Fixed qualified type detection in sphinx docstrings
Fixes #949
-rw-r--r--pylint/extensions/_check_docs_utils.py26
-rw-r--r--pylint/test/extensions/test_check_docs.py19
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 7916f49b1..9d12a8511 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
-------