Black: Black introduces E302 with a Comment at Line 0 and no Imports

Created on 18 Mar 2018  ·  8Comments  ·  Source: psf/black

Operating system: Debian 9
Python version: 3.6.4
Black version: black.py, version 18.3a2

Black converts this:

# License/Header comment

def includeme(config):
    pass

into this:

# License/Header comment
def includeme(config):
    pass

which causes this:

./compute/storage/__init__.py:14:1: E302 expected 2 blank lines, found 0
bug comments

Most helpful comment

Oh I'm already a donor to PSF. I'll have to increase my donation! :)

All 8 comments

Thanks for your report, I will be dealing with empty lines for the next release!

Thanks for the quick turn-around! Do you have a donation link?

Thanks for asking! I appreciate that. I don't intend to make money by working on Black.

I invite you to donate to the Python Software Foundation instead. This organization protects our trademarks, sponsors development sprints and conferences, and so on.

Oh I'm already a donor to PSF. I'll have to increase my donation! :)

This is now fixed in 18.3a3! Thanks! ✨ 🍰 ✨

I'm not sure if this is a regression, or if classes are handled differently, but I have the following code:

newline here
newline here
# -----
# something
# -----
class FooState:
    YES = "yes"
    NO = "no"

which black reformats to:

no newlines at all
# -----
# something
# -----
class FooState:
    YES = "yes"
    NO = "no"

which results in:

E302 expected 2 blank lines, found 0

Should I open a new issue? Is this expected behavior and flake8 is just wrong?

flake8 is wrong, you don't have to have those pointless empty new lines at the start of the file.

I figured as much. I disabled E302 given I want to let black handle all "formatting"-related concerns. Thanks for the quick reply!

Was this page helpful?
0 / 5 - 0 ratings