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

E306: False positive when preceded by 2 blank lines and a comment #1011

Open
ryangalamb opened this issue Sep 3, 2021 · 0 comments
Open

Comments

@ryangalamb
Copy link

$ pycodestyle --version
2.7.0

If you have two blank lines, a comment, and then a nested function, E306 is raised erroneously.
(Since this false positive requires a genuine violation of E303, I don't think it's a big deal. But I noticed it, so I'm reporting it.)

The following functions both trigger false postives for E306.

def bad():
    _ = None


    # arbitrary comment

    def inner():  # E306 not expected (but happening! 1/2)
        pass
def bad():
    _ = None


    # arbitrary comment
    def inner():  # E306 not expected (but happening! 2/2)
        pass

For context, this snippet contains the false positives as well as cases that don't trigger E306:

def bad():
    _ = None


    # arbitrary comment

    def inner():  # E306 not expected (but happening! 1/2)
        pass


def bad():
    _ = None


    # arbitrary comment
    def inner():  # E306 not expected (but happening! 2/2)
        pass


def good():
    _ = None
    # arbitrary comment


    def inner():  # E306 not expected
        pass


def good():
    _ = None

    # arbitrary comment
    def inner():  # E306 not expected
        pass


def good():
    _ = None

    # arbitrary comment

    def inner():  # E306 not expected
        pass

If you dump that to a file (e.g., bug.py) and run pycodestyle on it, you'll get E306 inside the two bad() functions:

$ pycodestyle --select=E306 --show-source bug.py
bug.py:7:5: E306 expected 1 blank line before a nested definition, found 0
    def inner():  # E306 not expected (but happening! 1/2)
    ^
bug.py:16:5: E306 expected 1 blank line before a nested definition, found 0
    def inner():  # E306 not expected (but happening! 2/2)
    ^

Let me know if there's anything I can clarify/provide, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant