diff options
author | Ashley Whetter <AWhetter@users.noreply.github.com> | 2018-02-16 22:10:10 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-16 22:10:10 -0800 |
commit | bd38d67ab5cba0d850c54753677c8f5f40b38004 (patch) | |
tree | 08ba00741be7a4b5e50b8bc85e23d1c8732d66f3 /pylint | |
parent | 3474c122aa31fce813c4427bd79097ee8099d0ee (diff) | |
download | pylint-git-bd38d67ab5cba0d850c54753677c8f5f40b38004.tar.gz |
Fixed false positive when a numpy Attributes section follows a Parameters section (#1878)
Fixes #1867
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/extensions/_check_docs_utils.py | 12 | ||||
-rw-r--r-- | pylint/test/extensions/test_check_docs.py | 23 |
2 files changed, 35 insertions, 0 deletions
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index bd5242f83..5da3250a2 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 3950cedb9..50ec44d17 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) |