[英]pylint disabling a single line of code just produces another pylint error
The documentation in section 4.1 clearly states:第 4.1 节中的文档明确指出:
https://pylint.readthedocs.io/en/latest/faq.html#message-control https://pylint.readthedocs.io/en/latest/faq.html#message-control
4.1 Is it possible to locally disable a particular message? 4.1 是否可以在本地禁用特定消息?
Yes, this feature has been added in Pylint 0.11.是的,此功能已在 Pylint 0.11 中添加。 This may be done by adding “#pylint: disable=some-message,another-one” at the desired block level or at the end of the desired line of code这可以通过在所需的块级别或所需代码行的末尾添加“#pylint: disable=some-message,another-one”来完成
Great!伟大的! but it doesn't work.但它不起作用。 Boo.嘘。
I get the the following pylint error for the following line of code对于以下代码行,我收到以下 pylint 错误
W: 26, 2: Redefining built-in 'zip' (redefined-builtin)
try:
from itertools import izip as zip # pylint: disable=bad-builtin
except ImportError:
pass
But pylint just complains even louder about my attempt to shut it up:但是 pylint 更大声地抱怨我试图关闭它:
E: 26, 0: Bad option value 'bad-builtin' (bad-option-value)
I've also tried the error code # pylint: disable=W0141
, that also produces a similar error.我也试过错误代码# pylint: disable=W0141
,它也会产生类似的错误。
Any idea what I'm doing wrong?知道我做错了什么吗?
I have been in a similar situation.我也遇到过类似的情况。
class A:
pass
There are many warnings in pylint
for the code above, but I want to talk about old-style-class
.对于上面的代码, pylint
有很多警告,但我想谈谈old-style-class
。 In Python 2.7, you will get an old-style-class
error.在 Python 2.7 中,您将收到old-style-class
错误。 Of course, you can change your code like this:当然,您可以像这样更改代码:
class A(object):
pass
However, you will receive a useless-object-inheritance
warning in Python 3.但是,您将在 Python 3 中收到useless-object-inheritance
警告。
If you are writing a package compatible with python 2.7 and 3 and using pylint
, then you are down.如果您正在编写与 python 2.7 和 3 兼容的包并使用pylint
,那么您就失败了。
Yes, if it is accepted to disable either of old-style-class
or useless-object-inheritance
in a comment, you can go further.是的,如果可以在评论中禁用old-style-class
或useless-object-inheritance
,您可以更进一步。
In Python 2.7:在 Python 2.7 中:
# pylint: disable=old-style-class
class A:
pass
In Python 3:在 Python 3 中:
# pylint: disable=useless-object-inheritance
class A(object):
pass
Eventually, you will get a bad-option-value
, just the same as this question.最终,你会得到一个bad-option-value
,就像这个问题一样。
I have tried, but bad-option-value
can not be disabled locally in this case.我已经尝试过了,但是在这种情况下不能在本地禁用bad-option-value
。 I have to disable bad-option-value
in a pylint
configuration file, like .pylintrc
.我必须在pylint
配置文件中禁用bad-option-value
,比如.pylintrc
。
[TYPECHECK]
disable=bad-option-value
Note : My pylint
version is 1.9.4 in python 2.7, 2.2.2 in python 3.注意:我的pylint
版本在 python 2.7 中是 1.9.4,在 python 3 中是 2.2.2。
啊,简单的答案,它应该是# pylint: disable=bad-option-value
出现在括号中的错误消息中:
E: 26, 0: Bad option value 'bad-builtin' (bad-option-value)
When you get this message:当您收到此消息时:
W: 26, 2: Redefining built-in 'zip' (redefined-builtin)
You have to disable the exact error message you are getting (the one in parenthesis):您必须禁用您收到的确切错误消息(括号中的那个):
try:
from itertools import izip as zip # pylint: disable=redefined-builtin
except ImportError:
pass
That seems to work fine in pylint 2.5.这在 pylint 2.5 中似乎运行良好。
It can be annoying if you are testing with multiple versions of python or different venvs and the same code base and you get different errors.如果您使用多个版本的 python 或不同的 venvs 和相同的代码库进行测试并且得到不同的错误,这可能会很烦人。 Be sure you fix the version to one version across all your builds/tests.确保在所有构建/测试中将版本修复为一个版本。 It sounds like that may have happened here (not sure where you got bad-builtin
from).听起来这可能发生在这里(不确定你从哪里得到了bad-builtin
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.