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

时间:2015-06-25 18:57:40

标签: python emacs pyflakes flake8

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 个答案:

答案 0 :(得分:0)

此问题在此处,因为它在 emacs 网站上标记为 oftop ,但实际答案是:https://emacs.stackexchange.com/a/13762

无论如何,这段代码很好:

class A:
    pass


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

这也很好:

class A:
    pass


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

这会因E302 expected 2 blank lines found 1

而失败
class A:
    pass

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

错误是由类之间的一行引起的。可能这是你的问题