当我测试使用 Requests 的模块时, pylint 很合适并声称 various members of the Request object我使用的不存在。我怎样才能解决这个问题?我已经使用 --generated-members=objects 选项运行了 pylint。
例如,这段代码运行良好:
import requests
response = requests.get('https://github.com/timeline.json')
print response.content
但是 pylint 声称该字段不存在:
ID:E1103 Instance of 'Request' has no 'content' member (but some types could not be inferred)
最佳答案
pylint
可以配置警告和错误消息。
首先,您可以编写一个 ${HOME}/.pylintrc
来禁用所有 pylint 检查的某些消息。您可以使用 --generate-rc-file
选项生成此文件的默认版本。
(有关更多信息,请参阅 this 问题)。
您还可以在分析的源中进行配置。例如在文件的开头放置一些注释。这将禁用整个文件的消息。
注释的形式为:#pylint: disable=warning-code
,“warning-code”是找到的列表之一 here .
您还可以在本地禁用消息,将注释放在语句/表达式之前或旁边。
例如,这将禁用函数内代码的“C0322”警告:
def my_func():
#C0322 -> no space between operand and operator
#pylint: disable=C0322
return a+b
虽然将注释放在右边会为单行代码禁用它:
def my_func():
return a+b #pylint: disable=C0322
我认为在您的情况下,您可以在使用 request
的函数的开头添加注释,或者,如果您没有多次访问它,您可以在声明的权利。
关于python - 让 pylint 容忍请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443988/