有没有可能忽略一个特定的线路与pylint?

时间:2022-04-15 22:27:23

I have the following line in my header:

我的标题中有如下一行:

import config.logging_settings

This actually changes my python logging settings, but pylint thinks it is an unused import. I do not want to remove unused-import warnings in general so is it possible to just ignore this one specific line?

这实际上改变了我的python日志设置,但是pylint认为它是一个未使用的导入。我不希望在一般情况下删除未使用的导入警告,所以是否可以忽略这一行?

I wouldn't mind having a .pylintrc for this project so answers changing a config file will be accepted.

我不介意为这个项目设置一个.pylintrc,因此修改配置文件的答案将被接受。

Otherwise, something like this will also be appreciated:

否则,像这样的东西也会被欣赏:

import config.logging_settings # pylint: disable-this-line-in-some-way

3 个解决方案

#1


66  

Pylint message control is documented in the Pylint manual:

在Pylint手册中记录了Pylint消息控制:

Is it possible to locally disable a particular message?

Yes, this feature has been added in 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 0.11中。这可以通过添加#pylint: disable=some-message,以及在所需的块级别或在所需的代码行末尾添加另一个消息来实现

You can use the message code or the symbolic names.

您可以使用消息代码或符号名称。

The manual also has an example.

手册中也有一个例子。

There is a wiki that documents all pylint messages and their codes.

有一个wiki记录所有pylint消息及其代码。

#2


20  

import config.logging_settings # pylint: disable=W0611

That was simple and is specific for that line.

这很简单,对于这条线是特定的。

As sthenault kindly pointed out, you can and should use the more readable form:

正如sthenault善意地指出的,你可以而且应该使用可读性更好的表单:

import config.logging_settings # pylint: disable=unused-import

#3


4  

I believe what you're looking for is...

我相信你要找的是……

import config.logging_settings  # @UnusedImport

Note the double space before the comment to avoid hitting other formatting warnings.

注意在注释之前的双重空间,以避免触及其他格式警告。

Also, depending on your IDE (if you're using one), there's probably an option to add the correct ignore rule (eg in eclipse pressing Ctrl1 while the cursor is over the warning will auto-suggest @UnusedImport

另外,根据您的IDE(如果您正在使用IDE),可能有一个选项可以添加正确的忽略规则(例如在eclipse按下ctrl - l1时,当光标在警告上方时,将自动建议@UnusedImport

#1


66  

Pylint message control is documented in the Pylint manual:

在Pylint手册中记录了Pylint消息控制:

Is it possible to locally disable a particular message?

Yes, this feature has been added in 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 0.11中。这可以通过添加#pylint: disable=some-message,以及在所需的块级别或在所需的代码行末尾添加另一个消息来实现

You can use the message code or the symbolic names.

您可以使用消息代码或符号名称。

The manual also has an example.

手册中也有一个例子。

There is a wiki that documents all pylint messages and their codes.

有一个wiki记录所有pylint消息及其代码。

#2


20  

import config.logging_settings # pylint: disable=W0611

That was simple and is specific for that line.

这很简单,对于这条线是特定的。

As sthenault kindly pointed out, you can and should use the more readable form:

正如sthenault善意地指出的,你可以而且应该使用可读性更好的表单:

import config.logging_settings # pylint: disable=unused-import

#3


4  

I believe what you're looking for is...

我相信你要找的是……

import config.logging_settings  # @UnusedImport

Note the double space before the comment to avoid hitting other formatting warnings.

注意在注释之前的双重空间,以避免触及其他格式警告。

Also, depending on your IDE (if you're using one), there's probably an option to add the correct ignore rule (eg in eclipse pressing Ctrl1 while the cursor is over the warning will auto-suggest @UnusedImport

另外,根据您的IDE(如果您正在使用IDE),可能有一个选项可以添加正确的忽略规则(例如在eclipse按下ctrl - l1时,当光标在警告上方时,将自动建议@UnusedImport