Python 如何在 PyCharm 中禁用 PEP 8 的特殊命名约定检查

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33153270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:52:52  来源:igfitidea点击:

How to disable special naming convention inspection of PEP 8 in PyCharm

pythonpycharmpep8jetbrains-ide

提问by ya_dimon

I installed PyCharm and enabled pep8checks in Inspections. If I write:

我安装了 PyCharm 并启用pep8Inspections. 如果我写:

def func(argOne):
    print(argOne)

The IDE shows me this warning: Argument name should be lowercase

IDE 向我显示此警告: Argument name should be lowercase

There is no option to ignore onlysuch inspection.
I cant find such error number to ignore in pep8
hereare allthe naming inspections.
how to ignore only someof them?

没有选择忽略此类检查。
我找不到这样的错误号忽略pep8
这里所有的命名检查。
如何忽略其中的一些?

I need this because the current project coding guidelines must be kept. It's too hard to change the guidelines of the whole project.

我需要这个,因为必须保留当前的项目编码指南。改变整个项目的指导方针太难了。

I need to disable only somenaming inspections. Not alllike by "Settings"-> "Editor"-> "Inspections"->"PEP8 coding style violation".
e.g. class names should be still inspected with PEP8, and function argument names not.

需要禁用一些命名检查。不是所有的都喜欢"Settings"-> "Editor"-> "Inspections"->"PEP8 coding style violation"
例如,类名仍应使用 PEP8 进行检查,而函数参数名称则不应。

采纳答案by Cani

Since PyCharm 2.7you can hover over the inspected code and use the light bulbto Ignore errors like this.

PyCharm 2.7 开始,您可以将鼠标悬停在检查过的代码上并使用灯泡忽略这样的错误

highlighted codeignore errors

highlighted codeignore errors

Further more you can manage the ignored errors at Settings > Editor > Code Style > Inspections > PEP 8 naming convention violation > Ignored errors

此外,您可以在设置 > 编辑器 > 代码样式 > 检查 > PEP 8 命名约定违规 > 忽略的错误中管理忽略的错误

pep8 naming convention settings

pep8 naming convention settings

Tested in PyCharm Community Edition 2016.3.2

在 PyCharm 社区版 2016.3.2 中测试

Edit:

编辑:

To remove the modification later on you can use filter buttonto Show Only Modified Inspectionsand delete the Ignored errorswith remove button

以后要删除修改你可以使用filter button仅显示已修改的检查和删除忽略的错误remove button

inspection filter

inspection filter

Tested in PyCharm Community Edition 2017.2.3

在 PyCharm 社区版 2017.2.3 中测试

回答by Leb

As it stands right now the only way to prevent that specific naming convention from pep8 is to disable it altogether through Settings> Inspections> Python, or simply leave as is.

就目前而言,阻止 pep8 使用特定命名约定的唯一方法是通过Settings> Inspections>完全禁用它Python,或者只是保持原样。

回答by arcseldon

Using PyCharm 5 (community edition), you can do the following. Code -> Inspect Code. Then select the required inspection error, and click on the "Suppress" option on right hand side. Please see screenshot below:

使用PyCharm 5(社区版),您可以执行以下操作。代码 -> 检查代码。然后选择所需的检查错误,并单击右侧的“抑制”选项。请看下面的截图:

PyCharm 5 Inspection

PyCharm 5 Inspection

Once you have done this, it adds a comment as shown in screenshot below:

完成此操作后,它会添加一条评论,如下面的屏幕截图所示:

Result

Result

As already mentioned in other comments, you should perhaps question why you are suppressing PEP8 guidelines. However, sometimes it appears necessary, for instance using the pytest module it is necessary to shadow variables etc which PEP8 Inspection complains about in which case this feature in PyCharm is very helpful.

正如其他评论中已经提到的,您或许应该质疑为什么要禁止 PEP8 指南。然而,有时它似乎是必要的,例如使用 pytest 模块有必要隐藏 PEP8 检查抱怨的变量等,在这种情况下,PyCharm 中的此功能非常有用。

回答by Erik Bethke

Argh! This was frustrating to me as well.

啊!这也让我很沮丧。

It is the onlywarning I disagree with. Anyways, you can fix it by flicking this checkbox in the image.

这是我不同意的唯一警告。无论如何,您可以通过轻弹图像中的此复选框来修复它。

How to turn off the warnings against camelCase

How to turn off the warnings against camelCase