Flake 8:"multiple statements on one line (colon)" 仅适用于以 "if" 开头的变量名称

Flake 8: "multiple statements on one line (colon)" only for variable name starting with "if"

我在 Visual Studio 代码中使用 flake8,使用 Python 3.6 variable annotations 编写一些代码。到目前为止它没有任何问题,但我遇到了一个奇怪的警告。

这很好用:

style: str = """
width: 100%;
...
"""
# Doing sth with `style`

这也是:

img_style: str = """
width: 100%;
...
"""
# Doing sth with `img_style`

但这并没有,它产生以下警告:

iframe_style: str = """
width: 100%;
...
"""
# Doing sth with `iframe_style`

好吧,从技术上讲它确实工作得很好;代码运行。但不知何故 flake8 对此并不满意。 多行字符串和后面的代码总是相同的。

当我省略 "f" (i_rame_style) 时,我也没有收到警告!所以我猜出于某种原因 flake8 在这里想到了 if foo: bar()!?

我在这里错过了什么?这是 flake8 中的错误吗?

编辑:问题出在 pycodestyle (pep8) 中,由 flake8 调用。剩下的还在原地。

第二次编辑:我做了更多研究,问题已解决 here。不过,该修复程序尚未发布。

在我看来绝对像一个 flake8 错误:

flakebug.py:

innocuous: str = ""
ifstarting_string: str = ""
forfalse_positivetoo: str = ""
whilethis_lookslikeabug: str = ""
elsehaha: str = ""

在shell中:

$ # python3.6 -m pycodestyle flakebug.py gives the same results
$ python3.6 -m flake8 flakebug.py 
flakebug.py:2:18: E701 multiple statements on one line (colon)
flakebug.py:3:21: E701 multiple statements on one line (colon)
flakebug.py:4:24: E701 multiple statements on one line (colon)
flakebug.py:5:9: E701 multiple statements on one line (colon)

看起来以控制流语句开头的每一行都会触发它。 我敢打赌它使用像 (if|else|while|for).*:.

这样的正则表达式

我会尽力弄清楚这个问题并尽可能更新这个答案,同时你可以添加一些 # noqa 注释,你会被设置:)