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

Black does not fix missing newline (flake8 E302) before comment + class definition #3360

Closed
kerrickstaley opened this issue Oct 27, 2022 · 1 comment
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@kerrickstaley
Copy link

Describe the bug

In the following code:

import math

# a most excellent class
class MyClass:
    PI = math.pi

Black fails to add an extra newline before the comment. This causes flake8 to give an E302 error.

Black does add a newline if you delete the comment, so I think this is an issue with Black.

To Reproduce
Run this in Bash on a Linux/Unix system:

cat > foo.py <<EOF
import math

# a most excellent class
class MyClass:
    PI = math.pi
EOF

python3 -m black foo.py
python3 -m flake8 foo.py

black will output

All done! ✨ 🍰 ✨
1 file left unchanged.

and flake8 will output

foo.py:4:1: E302 expected 2 blank lines, found 1

Expected behavior

Black adds a newline, and flake8 does not produce an error.

Environment

$ python3 -m black --version
python -m black, 22.10.0 (compiled: yes)
Python (CPython) 3.10.8
$ python3 -m flake8 --version                  
5.0.4 (mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0) CPython 3.10.8 on Darwin
$ python3 --version
Python 3.10.8
$ sw_vers
ProductName:	macOS
ProductVersion:	12.5
BuildVersion:	21G72
@kerrickstaley kerrickstaley added the T: bug Something isn't working label Oct 27, 2022
@felix-hilden
Copy link
Collaborator

Hi, this has been just fixed in --preview (playground example, #3302) coming your way in the next release. I'll close this issue as a duplicate!

@felix-hilden felix-hilden added the R: duplicate This issue or pull request already exists label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants