Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checker): update D202 for inner functions #395

Open
wants to merge 1 commit into
base: master
from

Conversation

@lewisacidic
Copy link

lewisacidic commented Aug 5, 2019

Changes D202: No blank lines allowed after function docstring to allow
space below function docstrings with inner functions:

i.e. allows

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

    def inner():
        pass

    return pass

See comment from @cdeil in #361.

Thanks for submitting a PR!

Please make sure to check for the following items:

  • Add unit tests and integration tests where applicable.
    If you've added an error code or changed an error code behavior,
    you should probably add or change a test case file under tests/test_cases/ and add
    it to the list under tests/test_definitions.py.
    If you've added or changed a command line option,
    you should probably add or change a test in tests/test_integration.py.
  • Add a line to the release notes (docs/release_notes.rst) under "Current Development Version".
    Make sure to include the PR number after you open and get one.

Please don't get discouraged as it may take a while to get a review.

@lewisacidic lewisacidic force-pushed the lewisacidic:feat/D202-inner branch from a7f15ed to 8931c7f Aug 5, 2019
lewisacidic added a commit to lewisacidic/pydocstyle that referenced this pull request Aug 5, 2019
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 PyCQA#361.

feat(checker): add test case to test_definitions

docs(changelog): add change to release notes
@lewisacidic lewisacidic force-pushed the lewisacidic:feat/D202-inner branch from 8931c7f to 410d677 Aug 5, 2019
lewisacidic added a commit to lewisacidic/pydocstyle that referenced this pull request Aug 5, 2019
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 PyCQA#361.

feat(checker): add test case to test_definitions

docs(changelog): add change to release notes
@lewisacidic

This comment has been minimized.

Copy link
Author

lewisacidic commented Aug 5, 2019

Dirty-looking change to fix the compatibility clash with black when it comes to inner functions.

I didn't take long to look through the library for a nicer way to do this, just thought I would get the ball rolling. Would be nice to have, as I have to disable D202 for our projects otherwise.

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
@lewisacidic lewisacidic force-pushed the lewisacidic:feat/D202-inner branch from 410d677 to f8b9419 Aug 5, 2019
Copy link

Code0x58 left a comment

👍 for taking the initiative

@@ -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')

This comment has been minimized.

Copy link
@Code0x58

Code0x58 Sep 14, 2019

To allow both classes and functions and avoid including variables that have a name starting with def you could use:

re(r"\s+(?:class|def)\s").match(after)

This follows how python's re module is used in this file, where re is an alias for re.compile. It would be good to add a test for the class case too.

The check docstring could use updating to reflect the allowance of a single line if it is before a class/function definition. Same goes for the violation descriptions.

@johanfleury

This comment has been minimized.

Copy link
Contributor

johanfleury commented Oct 24, 2019

@lewisacidic are you still working on this?

I see there's not much left to do (fix the docstring at the top of functions.py, use re as asked by @Code0x58), I can probably take it over if you can't (or don't want to) work on this PR anymore?

@lewisacidic

This comment has been minimized.

Copy link
Author

lewisacidic commented Oct 24, 2019

Oh sorry completely forgot about this - I'm really busy until end of next week. I could come back to it then, but feel free to finish off if you want!

btw sorry for brutalizing this with force pushes...

@johanfleury

This comment has been minimized.

Copy link
Contributor

johanfleury commented Oct 24, 2019

I created PR #426 with @Code0x58 recommendation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.