Pylint为'http.HTTPStatus'提供了错误的肯定的E1101'no-member'错误

时间:2019-07-05 19:27:34

标签: python http http-status-codes pylint pylintrc

我正在使用pylint进行代码替换(在带有pylint 2.3.1,astroid 2.2.5,Python 3.6.2的VS Code内部)。

可以使用以下代码段重现该行为:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from http import HTTPStatus

print(HTTPStatus.NOT_ACCEPTABLE.phrase)

调用该代码段

$ pylint snippet.py 

给出以下错误消息:

E1101: Instance of 'NOT_ACCEPTABLE' has no 'phrase' member (no-member)

但是,由于代码正在运行,我认为.phrase是给定实例的成员,可以打印所需的结果,并且docs中引用了.phrase。这导致错误消息为假阳性的假设。

然后,我查看了its own documentationVS Code docs中的pylint配置选项,并通过执行生成了.pylintrc文件

pylint --generate-rcfile > .pylintrc

在此配置文件中,我可以找到以下行:

enable=c-extension-no-member

注释掉此行,从而禁用c-extension-no-member检查,可以抑制误报E1101错误消息。但是,我仍然想知道这仅仅是解决方法还是真正的误报,因为它会禁用所有c-extension-no-member检查,并且似乎不适合一般方法。当然,可以指定执行检查时要忽略的特定模块,但我只想知道此错误消息的原因。

0 个答案:

没有答案