在pylint中,有没有一种方法可以在本地禁用警告,然后在没有显式给出列表的情况下撤消先前的抑制? [英] In pylint is there a way to locally disable a warning and then undo the previous suppression without explicitly giving a list?

查看:255
本文介绍了在pylint中,有没有一种方法可以在本地禁用警告,然后在没有显式给出列表的情况下撤消先前的抑制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 FAQ 的PyLint条目,其中指出:

I am aware of the FAQ entry for PyLint which states that:


4.2是否有禁用方法



是的,您可以通过在
模块级别添加相应的选项来禁用或启用(全局禁用)消息。在文件的
顶部注释:

4.2 Is there a way to disable a message for a particular module only?

Yes, you can disable or enable (globally disabled) messages at the module level by adding the corresponding option in a comment at the top of the file:

# pylint: disable=wildcard-import, method-hidden
# pylint: enable=too-many-lines


,如何在抑制之前本地抑制消息,然后简单地恢复以前的状态。恢复以前的状态时,我不想重复自己。有没有办法做到这一点?

However, how can I locally suppress a message and then simply restore the previous state, prior to suppression. I don't want to have to repeat myself when restoring the previous state. Is there a way to achieve this?

PyLint处理此问题的方式的一个缺陷似乎是,如果我禁用了特定消息,则 some-message 全局(例如命令行或 pylintrc ),然后有以下Python代码段:

A shortcoming of the way PyLint handles this appears to be that if I disable a particular message some-message globally (e.g. command line or pylintrc) and then I have the following Python code segment:

# pylint: disable=some-message
foo, bar, baz = 0, 1, 2
# ... the code that creates the warning
# pylint: enable=some-message

文档表明第一行没有任何效果(即,已禁用的消息将保持禁用状态),而最后一行不仅会撤消第一行的局部效果(无论是由于全局设置是否是良性的),还会撤消命令行选项或 pylintrc 设置。

the documentation suggests that the first line would not have any effect (i.e. the already disabled message would remain disabled) while the last line would undo not just the local effect of the first line - whether it was benign or not due to global settings - but would also undo the command line option or pylintrc setting.

我正在寻找的功能类似于MS Visual C ++中的警告功能:

What I am looking for is a functionality similar to that in MS Visual C++ for warnings:

#pragma warning(push) /* save current state of warning settings */
#pragma warning(disable:somewarning)
/* warning occurs in code here */
#pragma warning(pop)  /* restore previous state of warning settings */

更简洁的选择是:

#pragma warning(disable:somewarning)
/* warning occurs in code here */
#pragma warning(default:somewarning)

PyLint中是否存在任何功能?

Does either functionality exist in PyLint?

推荐答案

pylint没有这种功能。您可能会在它的跟踪器上建议它: https://bitbucket.org/logilab/pylint/issues

There is no such functionnality in pylint. You may suggest it on its tracker though: https://bitbucket.org/logilab/pylint/issues

这篇关于在pylint中,有没有一种方法可以在本地禁用警告,然后在没有显式给出列表的情况下撤消先前的抑制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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