1

I'm using flake8 with emacs. If I begin a file with

# comment comment comment comment comment comment comment comment comment comment
class Foo(object):
    pass

It says there is no syntax error. But if I wrap it to:

# comment comment comment comment comment comment comment comment
# comment comment
class Foo(object):
    pass

I get "E302 expected 2 blank lines, found 0" for the "class" line.

Is this a bug? Can it be fixed with a config setting?

2
  • 1
    Isn't this more a question about flake8 and less about Emacs?
    – user227
    Commented Jul 7, 2015 at 20:49
  • I wasn't sure at the time I asked. I'm still not 100% sure. Should I delete it if so? Commented Jul 7, 2015 at 23:13

1 Answer 1

0

I am not sure why there is a difference between your single-line comment and multi-line comment examples, but my assumption is that it is not a bug - at least the "E302 expected 2 blank lines, found 0" part shouldn't be. If there is a bug, it is likely that the E302 should show up in both cases, rather than just the multiline version. Flake8 is meant to help you get PEP8 compliant, and PEP8 stipulates that you should "(s)urround top-level function and class definitions with two blank lines". So this is why you are seeing the message you are seeing in the multi-line comment case. Try your second example as:

# comment comment comment comment comment comment comment comment
# comment comment


class Foo(object):
    pass

Or better yet:

"""
comment comment comment comment comment comment comment comment
comment comment
"""


class Foo(object):
    pass

And I assume you won't get the message.

3
  • It's definitely a bug if the warning triggers with the wrapped line and not the unwrapped line. As to your suggestion, PEP8 doesn't say anything about comments with regard to spacing. The two lines thing definitely refers to other definitions, but not necessarily to comments. If I add a second definition like my first with two spaces between them, I won't get a warning. People always put block comments directly above the code. I've never seen examples like yours with spaces between the comment and the commented code. I don't even know what's up with the docstring; what is it the docstring of? Commented Jul 7, 2015 at 18:55
  • Since you mentioned that the code was at the beginning of the file, I assumed that the # comments were meant as a module-level docstring, in which case I think the convention is generally to use triple quotes like in my second example. I assume that if you have the example code in the middle of a file surrounded by other working code, it still gives you the same message? My initial thought was that the error was being raised because of the way the start of your file was structured.
    – elethan
    Commented Jul 8, 2015 at 1:35
  • Oh, I see. No, it was implementation-detail comments for a specific class, so not for docstring. You don't get that error in the middle of the file, assuming you have space between the last block and the comment above the new block. Commented Jul 8, 2015 at 23:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.