summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Whetter <AWhetter@users.noreply.github.com>2018-02-16 22:10:10 -0800
committerAshley Whetter <asw@dneg.com>2018-07-26 11:43:07 -0700
commit41d68b57bb6dd93493291e3efe90945a99a23339 (patch)
treeda2e8e5a8f611b53361563c93525b82ee68bbbd6
parentf22732960067a36d212f5210d2b36ab029ec38ab (diff)
downloadpylint-git-41d68b57bb6dd93493291e3efe90945a99a23339.tar.gz
Fixed false positive when a numpy Attributes section follows a Parameters section (#1878)
Fixes #1867
-rw-r--r--ChangeLog11
-rw-r--r--pylint/extensions/_check_docs_utils.py12
-rw-r--r--pylint/test/extensions/test_check_docs.py23
3 files changed, 46 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f795cb0e7..d372b303d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,17 @@
Pylint's ChangeLog
------------------
+What's New in Pylint 1.9.4?
+===========================
+
+Release date: |TBA|
+
+ * Fixed false positive when a numpy Attributes section follows a Parameters
+ section
+
+ Close #1867
+
+
What's New in Pylint 1.9.3?
===========================
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py
index 2a0d9c3b4..8a7dc7651 100644
--- a/pylint/extensions/_check_docs_utils.py
+++ b/pylint/extensions/_check_docs_utils.py
@@ -609,6 +609,12 @@ class GoogleDocstring(Docstring):
def min_section_indent(section_match):
return len(section_match.group(1)) + 1
+ @staticmethod
+ def _is_section_header(_):
+ # Google parsing does not need to detect section headers,
+ # because it works off of indentation level only
+ return False
+
def _parse_section(self, section_re):
section_match = section_re.search(self.doc)
if section_match is None:
@@ -633,6 +639,8 @@ class GoogleDocstring(Docstring):
is_first = False
if indentation == min_indentation:
+ if self._is_section_header(line):
+ break
# Lines with minimum indentation must contain the beginning
# of a new parameter documentation.
if entry:
@@ -703,3 +711,7 @@ class NumpyDocstring(GoogleDocstring):
@staticmethod
def min_section_indent(section_match):
return len(section_match.group(1))
+
+ @staticmethod
+ def _is_section_header(line):
+ return bool(re.match(r'\s*-+$', line))
diff --git a/pylint/test/extensions/test_check_docs.py b/pylint/test/extensions/test_check_docs.py
index d2efbfdad..593ebce5f 100644
--- a/pylint/test/extensions/test_check_docs.py
+++ b/pylint/test/extensions/test_check_docs.py
@@ -750,6 +750,29 @@ class TestParamDocChecker(CheckerTestCase):
):
self._visit_methods_of_class(node)
+ def test_constr_params_and_attributes_in_class_numpy(self):
+ """Example of a class with correct constructor parameter documentation
+ and an attributes section (Numpy style)
+ """
+ node = astroid.extract_node("""
+ class ClassFoo(object):
+ '''
+ Parameters
+ ----------
+ foo : str
+ Something.
+
+ Attributes
+ ----------
+ bar : str
+ Something.
+ '''
+ def __init__(self, foo):
+ self.bar = None
+ """)
+ with self.assertNoMessages():
+ self._visit_methods_of_class(node)
+
def test_constr_params_in_init_sphinx(self):
"""Example of a class with missing constructor parameter documentation
(Sphinx style)