【问题标题】:how to fix: flake8/pyflakes treats multiline comment before class as error如何修复:flake8/pyflakes 将课堂前的多行注释视为错误
【发布时间】:2015-06-25 18:57:40
【问题描述】:

我将 flake8 与 emacs 一起使用。如果我以

开头的文件
# comment comment comment comment comment comment comment comment comment comment
class Foo(object):
    pass

它说没有语法错误。但如果我把它包装成:

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

对于“class”行,我得到“E302 预期 2 个空白行,找到 0”。

这是一个错误吗?可以通过配置设置修复吗?

【问题讨论】:

  • 你为什么把cmets放在课前?如果它们与该类有关,则它们应该是其中的docstring。如果没有,应该有空格来表示。
  • 在这种情况下,cmets 是实现细节,而不是课堂用户的注释。
  • 我明白了。一般来说:是的,您可以配置所需的警告,例如与# noqa。有关您正在使用的工具,请参阅文档。如有必要,您还可以扩展flake8
  • 如果您认为这是一个错误,请向开发人员提出。

标签: python emacs pyflakes flake8


【解决方案1】:

这个问题在这里,因为它在 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
    """

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 2019-07-03
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多