是否可以使用 Pylint 忽略单个特定行? [英] Is it possible to ignore one single specific line with Pylint?

查看:34
本文介绍了是否可以使用 Pylint 忽略单个特定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的标题中有以下行:

import config.logging_settings

这实际上改变了我的 Python 日志记录设置,但 Pylint 认为这是一个未使用的导入.我一般不想删除 unused-import 警告,那么是否可以忽略这一特定行?

我不介意这个项目有一个 .pylintrc,因此将接受更改配置文件的答案.

否则,这样的事情也会受到赞赏:

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

解决方案

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

<块引用>

是否可以在本地禁用特定消息?

是的,此功能已在 Pylint 0.11 中添加.这可以通过添加来完成# pylint: disable=some-message,another-one在所需的块级或所需代码行的末尾.

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

例如

def test():# 禁用此函数中的所有无成员违规# pylint: 禁用=无成员...

global VAR # pylint: disable=global-statement

该手册还有更多示例.

维基记录了所有 Pylint 消息及其代码.

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?

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

Otherwise, something like this will also be appreciated:

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

解决方案

Pylint message control is documented in the Pylint manual:

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.

You can use the message code or the symbolic names.

For example,

def test():
    # Disable all the no-member violations in this function
    # pylint: disable=no-member
    ...

global VAR # pylint: disable=global-statement

The manual also has further examples.

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

这篇关于是否可以使用 Pylint 忽略单个特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆