抑制 pycharm 和 pylint 的警告 [英] Suppress warning for both pycharm and pylint

查看:72
本文介绍了抑制 pycharm 和 pylint 的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 PyCharm 编写代码,并且我还配置了 CI 服务器以在每个 PR 上运行 PyLint.问题是 PyCharm 和 PyLint 使用不同的注释进行警告抑制:

I use PyCharm to write code and I also have CI server configured to run PyLint on every PR. The problem is PyCharm and PyLint use different comments for warning suppression:

# noinspection PyMethodMayBeStatic
# pylint: disable=no-self-use

我不喜欢对 PyCharm 和 PyLint 有两个评论.有没有办法配置 PyLint 来理解 PyCharm 注释或配置 PyCharm 来理解 PyLint 注释?

I don't like having two comments for both PyCharm and PyLint. Is there a way to configure PyLint to understand PyCharm comments or to configure PyCharm to understand PyLint comments?

推荐答案

有没有办法配置 PyLint 来理解 PyCharm 注释或配置 PyCharm 以理解 PyLint 注释?

Is there a way to configure PyLint to understand PyCharm comments or to configure PyCharm to understand PyLint comments?

没有.至少目前我不知道.你总是可以写一些东西,尽管我相信有一个更简单的选择.

No. At least not currently that i am aware of. You could always write something, although i believe there is a simpler option.

我正在寻找一种方法让 PyC​​harm 理解 PyLint 语法,这是像 # pylint: disable=unused-argument 这样的评论来抑制特定的 linter 警告.

I am looking for a way to make PyCharm understand the PyLint syntax, that is comments like # pylint: disable=unused-argument to supress specific linter warnings.

与其让PyCharm 理解 PyLint 语法",不如 PyLint 与 PyCharm 集成:

Rather than make "PyCharm understand the PyLint syntax" Why not integrate PyLint with PyCharm:

Within PyCharm:

    Navigate to the preferences window
    Select "External Tools"
    Click the plus sign at the bottom of the dialog to add a new external task
    In the dialog, populate the following fields:
    Name:   Pylint
    Description:    A Python source code analyzer which looks for programming errors, helps enforcing a coding standard and sniffs for some code smells.
    Synchronize files after execution:
        unchecked
    Program:    /path/to/pylint
    Parameters: $FilePath$
    Click OK

The option to check the current file with Pylint should now be available in Tools > External Tools > Pylint.

然后在 PyCharm 中禁用 PyCharm 特定警告.现在您只需要使用 PyLint 警告.我意识到这不是你想要的,但我希望它有所帮助.它至少对我有用.仅使用 PyLint 警告的好处是与使用其他编辑器的人共享代码更简单.

Then in disable the PyCharm specific warnings in PyCharm. Now you only need to use the PyLint warnings. I realise this isn't exactly what you wanted but i hope it helps. It works for me atleast. The nice thing about using only PyLint warnings is that sharing the code with people who use other editors is simpler.

这篇关于抑制 pycharm 和 pylint 的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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