简体   繁体   English

Pylint:如何在没有后续“压制消息”废话的情况下干净地压制事物?

[英]Pylint: How do I cleanly suppress things without subsequent 'suppressed-message' nonsense?

I have a file foo.py that makes extensive use of the Faker third-party module. 我有一个文件foo.py,广泛使用Faker第三方模块。 As such, pylint generates a lot of 'no-member' errors. 因此,pylint会产生很多“无成员”错误。

I would like to disable these in foo.py. 我想在foo.py中禁用它们。 So at the top, I tried inserting: 所以在顶部,我尝试插入:

# pragma pylint: disable=no-member

But, in a quite-annoying fashion, pylint now spits out a suppressed message every time it hits one of these errors - completely defeating the purpose of my pragma?? 但是,以一种非常烦人的方式,pylint现在每次遇到其中一个错误时都会发出一条被抑制的消息 - 完全打败了我的pragma的目的?

foo.py:1:0: I0011: Locally disabling no-member (E1101) (locally-disabled)
... other misc stuff ...
foo.py:177:0: I0020: Suppressed 'no-member' (from line 1) (suppressed-message)
foo.py:83:0: I0020: Suppressed 'no-member' (from line 1) (suppressed-message)
foo.py:85:0: I0020: Suppressed 'no-member' (from line 1) (suppressed-message)

Huh... well that's... ridiculous. 嗯......好吧......太荒谬了。

So I tried to... suppress the suppression messages?? 所以我试着......压制抑制消息?

# pragma pylint: disable=no-member,suppressed-message

And THEN it gets even better... 然后它变得更好......

foo.py:1:0: I0011: Locally disabling no-member (E1101) (locally-disabled)
foo.py:1:0: I0011: Locally disabling suppressed-message (I0020) (locally-disabled)
foo.py:1:0: C0102: Black listed name "foo" (blacklisted-name)
.... misc stuff, actual things I should clean up here ...
foo.py:1:0: I0021: Useless suppression of 'suppressed-message' (useless-suppression)

So I guess my question is - how do I make suppression messages go away entirely on a per-file basis, without some annoying replacement message being dropped in? 所以我想我的问题是 - 如何在每个文件的基础上完全消除抑制消息,而不会丢弃一些烦人的替换消息?

EDIT: Thank you for the comments. 编辑:谢谢你的评论。

Output of pylint --version: 输出pylint --version:

pylint 2.1.1
astroid 2.0.4
Python 3.6.5 (default, Apr 25 2018, 14:23:58) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]

I-category messages are disabled by default. 默认情况下禁用I类消息。 You turned them on yourself, by setting enable=all in the [MESSAGES CONTROL] section of your pylintrc, and then you didn't disable them in the disable list in the same section. 你通过在pylintrc的[MESSAGES CONTROL]部分设置enable=all来自己打开它们,然后你没有在同一部分的disable列表中禁用它们。 Add suppressed-message to the disable list in your pylintrc, and the suppressed-message messages should stop appearing. suppressed-message添加到pylintrc中的disable列表中,抑制消息消息应该停止显示。

As for the useless-suppression message, that seems to be a pylint bug. 至于无用抑制消息,这似乎是一个pylint错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM