gpt4 book ai didi

python - 妖娆的代码能过pylint吗?

转载 作者:太空宇宙 更新时间:2023-11-04 05:53:42 25 4
gpt4 key购买 nike

我运行 pylint -E 作为我的 Python 项目测试的一部分,以确保错误不会蔓延到未经测试的代码中。通常这很有效。但最近我遇到了 voluptuous 的问题和皮林特。

问题在于 pylint 认为 voluptuous Schemas 返回的值是列表,而事实并非如此。这是一个玩具程序:

import voluptuous

MyType = voluptuous.Schema({
'q': str
})


def foo(bar):
bar = MyType(bar)
q = bar.get('q')
print q


foo({'q': '1324'})

它运行得很好:

$ python toy.py
1234

然而,pylint 标记了 .get() 调用:

$ pylint -E toy.py
No config file found, using default configuration
************* Module toy
E: 11, 8: Instance of 'list' has no 'get' member (no-member)

如何让这个程序通过pylint -E

最佳答案

一个选择是完全忽略 voluptuous 模块,例如

$ pylint -E --ignored-modules=voluptuous toy.py
(passes)

不过,如果 pylint 能更好地理解 voluptuous 就好了。

关于python - 妖娆的代码能过pylint吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28881460/

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