gpt4 book ai didi

python - 如何在 Python 3 中使用 flake8?

转载 作者:IT老高 更新时间:2023-10-28 22:22:39 26 4
gpt4 key购买 nike

在此代码段中,

def add(x:int, y:int) -> int:
return x + y

有些函数注解是python 3.0以后才支持的

当我为此 python 代码执行 flake8 时:

$ flake8 7.3.py -vv
checking 7.3.py
def add(x: int, y: int) -> int:
return x + y
7.3.py:1:11: E901 SyntaxError: invalid syntax

我收到了无效的语法错误,但它应该是有效的语法。如何使用 flake8 检查仅在 Python 3.x 中支持的语法?

最佳答案

见:https://bugs.launchpad.net/pyflakes/+bug/989203

注意:虽然此错误报告表明了某种程度的解决方案,但测试最新版本的 pyflakes 0.8.1 仍然存在 Python 3 注释的缺失。

我猜你必须向 pyflakes 提交单独的新功能请求。

pyflakes Bugs

$ cat - > foo.py
def add(x:int, y:int) -> int:
return x + y
^D
$ pyflakes --version
0.8.1

$ pyflakes foo.py
foo.py:1:10: invalid syntax
def add(x:int, y:int) -> int:
^

更新(20140514):

事实证明,这个问题的实际答案是运行 pyflakesflake8在 Python 3.x 而不是 Python 2.x 下。这是有道理的:)

所以做这样的事情:

/usr/bin/python3 -m pyflakes foo.py

见:http://codepad.org/9BKxSZaD

关于python - 如何在 Python 3 中使用 flake8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23600614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com