how to fix: flake8/pyflakes treats multiline comment before class as error

1.5k views Asked by At

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?

1

There are 1 answers

1
maxkoryukov On

This question is here, because it was marked oftop on emacs site, but the actual answer is there: https://emacs.stackexchange.com/a/13762

Anyway, this code is good:

class A:
    pass


# two empty lines above and comment comment comment comment
class B:
    """
    About class B
    """

This is good too:

class A:
    pass


# two empty lines above and a comment
# comment
class B:
    """
    About class B
    """

And this will fail with E302 expected 2 blank lines found 1

class A:
    pass

# comment
# comment
class B:
    """
    About class B
    """

The error is caused by one line between classes. Probably, this is what your question about