我在 Visual Studio Code 中使用 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
中的错误吗?
最佳答案
编辑:问题出在由 flake8 调用的 pycodestyle (pep8) 中。其余的仍然存在。
第二次编辑:我做了更多研究,问题已解决 here .不过,该修复程序尚未发布。
在我看来绝对像一个 flake8 错误:
flakebug.py
:
innocuous: str = ""
ifstarting_string: str = ""
forfalse_positivetoo: str = ""
whilethis_lookslikeabug: str = ""
elsehaha: str = ""
在外壳中:
$ # 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
注释,然后你就可以了:)
关于python - 片状 8 : "multiple statements on one line (colon)" only for variable name starting with "if",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49774397/