google / google/yapf

Inconsistency in number of blank lines prior to function definition following a comment

Open
#331 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Consider the following code:

``` python
try:
a = 1
# Hi

def e():
pass
except:
pass
```

yapf (with --style=pep8) lays it out as follows:

``` python
try:
a = 1

# Hi

def e():
pass
except:
pass
```

But without the assignment, yapf introduces one fewer blank line following the comment:

``` python
try:
# Hi

def e():
pass
except:
pass
```

``` python
try:
# Hi

def e():
pass
except:
pass
```

The reason this is particularly relevant is that it is an instance of yapf disagreeing with the pep8 style checker as to the correct number of blank lines. The style checker doesn't think this counts as a top level definition, and thus it is deserving of only one blank line rather than the more generous two yapf is giving it.

I acknowledge that you don't consider the pep8 checker a source of canonical truth, but this seems to be a similar issue to #24 in which its answer was deemed right.

I tested this running against a2f0342 under Python 3.5.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.