Skip to content

Black doesn't enforce two empty lines before functions on module level when they have a sticky leading comment #246

@hugovk

Description

@hugovk

Operating system: macOS High Sierra
Python version: 3.6.5
Black version: 18.5b0
pycodestyle version: 2.4.0
Does also happen on master: yes

Should Black insert a newline between these variables and the function?

pycodestyle complains about test.py but Black doesn't change it

$ cat test.py
from __future__ import print_function, unicode_literals

all_data = []
all_versions = set()

# Comment
def thing():
    pass
$ pycodestyle test.py
test.py:7:1: E302 expected 2 blank lines, found 1
$ black test.py
/private/tmp/test.py already well formatted, good job.

Both pycodestyle and Black are fine with test2.py

$ cat test2.py
from __future__ import print_function, unicode_literals

all_data = []
all_versions = set()


# Comment
def thing():
    pass
$ pycodestyle test2.py
$ black test2.py
/private/tmp/test2.py already well formatted, good job.

Black reformats test3.py, with no comment

$ cat test3.py
from __future__ import print_function, unicode_literals

all_data = []
all_versions = set()

def thing():
    pass
$ pycodestyle test3.py
test3.py:6:1: E302 expected 2 blank lines, found 1
$ black test3.py
reformatted /private/tmp/test3.py
$ pycodestyle test3.py
$ cat test3.py
from __future__ import print_function, unicode_literals

all_data = []
all_versions = set()


def thing():
    pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: commentsThe syntactic kind. Not in the language grammar, always on our minds. Best bugs.F: empty linesWasting vertical space efficiently.T: enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions