Flake 8:"在一行(冒号)上的多个语句"仅用于以"if"开头的变量名称

lin*_*usg 9 python python-3.x flake8 python-3.6 mypy

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

这很好用:

style: str = """
width: 100%;
...
"""
# Doing sth with `style`
Run Code Online (Sandbox Code Playgroud)

这个也是:

img_style: str = """
width: 100%;
...
"""
# Doing sth with `img_style`
Run Code Online (Sandbox Code Playgroud)

但是,这不会产生以下警告:

iframe_style: str = """
width: 100%;
...
"""
# Doing sth with `iframe_style`
Run Code Online (Sandbox Code Playgroud)

flake8警告

嗯,从技术上讲它确实很好; 代码运行.但不知何故flake8对此并不满意.多行字符串和后面的代码始终相同.

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

我在这里错过了什么?这是一个错误flake8吗?

ete*_*ene 8

编辑:问题出在pycodestyle(pep8),由flake8调用.其余的仍然存在.

第二次编辑:我做了一些更多的研究,问题在这里修复.但该修复程序尚未发布.

对我来说绝对看起来像一个flake8 bug:

flakebug.py:

innocuous: str = ""
ifstarting_string: str = ""
forfalse_positivetoo: str = ""
whilethis_lookslikeabug: str = ""
elsehaha: str = ""
Run Code Online (Sandbox Code Playgroud)

在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)
Run Code Online (Sandbox Code Playgroud)

看起来每个以控制流语句开头的行都会触发它.我打赌它使用正则表达式(if|else|while|for).*:.

如果可以的话,我会试着深究这个并更新这个答案,同时你可以添加一些# noqa注释,你将被设置:)