python - 片状 8 : "multiple statements on one line (colon)" only for variable name starting with "if"

标签 python python-3.x python-3.6 mypy flake8

我在 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 warning

嗯,从技术上讲它确实工作得很好;代码运行。但不知何故 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/

相关文章:

python - 对象 'user' 没有属性 'create' - Django

python - 如何替换函数的 __str__

python-3.x - 将Jupyter Notebook转换成MS Word文档.doc?

python - 如何查找计算机上所有创建/修改时间晚于特定日期的文件?

python - 如何使用 pk selected 在 ManyToMany 关系中使用 prefetch_lated

python - 在 TensorFlow KMean 类中解压的值太多

python - 属性错误 : module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer'

python - 一个接一个地执行多个条件,同时向用户显示哪个条件是第一个失败的Pythonic方法是什么

python - 如何在 python 中将字符串列表转换为整数?

python - 过滤包含非 ascii 值的 Pandas 数据框行