diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 12b36663..b010fcf2 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -13,6 +13,8 @@ Bug Fixes e.g., init and initialize / initiate (#382). * Fix parser hanging when there's a comment directly after ``__all__`` (#391, #366). +* D202: Allow a blank line after function docstring when the function begins with + an inner function (#361). 4.0.0 - July 6th, 2019 --------------------------- diff --git a/src/pydocstyle/checker.py b/src/pydocstyle/checker.py index a45648fa..98b73315 100644 --- a/src/pydocstyle/checker.py +++ b/src/pydocstyle/checker.py @@ -199,7 +199,9 @@ def check_no_blank_before(self, function, docstring): # def if blanks_before_count != 0: yield violations.D201(blanks_before_count) if not all(blanks_after) and blanks_after_count != 0: - yield violations.D202(blanks_after_count) + def_follows = after.split("\n")[2].lstrip().startswith('def') + if not (blanks_after_count == 1 and def_follows): + yield violations.D202(blanks_after_count) @check_for(Class) def check_blank_before_after_class(self, class_, docstring): diff --git a/src/tests/test_cases/functions.py b/src/tests/test_cases/functions.py new file mode 100644 index 00000000..d042508f --- /dev/null +++ b/src/tests/test_cases/functions.py @@ -0,0 +1,29 @@ +""" Function docstrings """ + +from .expected import Expectation + +expectation = Expectation() +expect = expectation.expect + + +@expect("D201: No blank lines allowed before docstring") +def func_with_space_before(): + + """Func with space before.""" + pass + + +@expect("D202: No blank lines allowed after docstring") +def func_with_space_after(): + """Func with space after.""" + + pass + + +def func_with_inner_func_after(): + """Func with inner after.""" + + def inner(): + pass + + pass diff --git a/src/tests/test_definitions.py b/src/tests/test_definitions.py index 2d8e9be4..3a17af75 100644 --- a/src/tests/test_definitions.py +++ b/src/tests/test_definitions.py @@ -19,6 +19,7 @@ 'superfluous_quotes', 'noqa', 'sections', + 'functions', ]) def test_complex_file(test_case): """Run domain-specific tests from test.py file."""