Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
feat(checker): change D202 for inner funcs (#395)
Browse files Browse the repository at this point in the history
Changes D202: "No blank lines allowed after function docstring" to
allow space below function docstrings with inner functions.

i.e. allows:

```python

def outer():
    """Valid docstring."""

    def inner():
        pass

    return pass
```

See comment from @cdeil in #361.

feat(checker): add test case to test_definitions

docs(changelog): add change to release notes
  • Loading branch information
lewisacidic committed Aug 5, 2019
1 parent 49183a3 commit f8b9419
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/pydocstyle/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
29 changes: 29 additions & 0 deletions src/tests/test_cases/functions.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/tests/test_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'superfluous_quotes',
'noqa',
'sections',
'functions',
])
def test_complex_file(test_case):
"""Run domain-specific tests from test.py file."""
Expand Down

0 comments on commit f8b9419

Please sign in to comment.