E306: False positive when preceded by 2 blank lines and a comment
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 754
- PR merge metrics
- No merged PRs in 30d
Description
$ 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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Save the supplied examples as bug.py and run pycodestyle --select=E306 --show-source bug.py to reproduce the two false positives. Read the E306 checker entry point in the project's single Python file, then verify the nested definitions preceded by comments and blank lines no longer report E306 while the existing cases retain their expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100