black
black copied to clipboard
Black does not fix missing newline (flake8 E302) before comment + class definition
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