Pycharm的代码样式检查:忽略/关闭特定规则 [英] Pycharm's code style inspection: ignore/switch off specific rules

查看:3419
本文介绍了Pycharm的代码样式检查:忽略/关闭特定规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将现有项目导入PyCharm。我可以重构代码,以便PyCharm会很高兴,但我们喜欢在字典中的冒号周围有空格,如下所示: {A:B} 。我们也喜欢调整作业:

I'm trying to import existing project into PyCharm. I can refactor the code so that PyCharm will be pleased, but we like to have spaces around colons in dictionaries, like this: {"A" : "B"}. We also like aligning assignments:

a   = 1
abc = 3

有没有办法配置PyCharm,以便他会忽略与这些特定内容相关的所有错误/警告?

Is there a way to configure PyCharm, so that he'll ignore all errors/warnings related to this specific stuff?

推荐答案

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

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 or "Ignore errors like this" option on right hand side. Please see screenshot below:

当您选择抑制选项时,它会添加注释,如下面的屏幕截图所示:

When you chose the "Suppress" option, it adds a comment as shown in screenshot below:

可以在语句和函数/方法级别进行抑制。如果试图抑制函数的参数,那么Suppress选项仅在函数级别起作用(这也会抑制在该函数中可能存在的其他名称引用违规,该函数已经抑制了样式约定)

Suppress can be made at the statement, and function / method levels. If trying to suppress an argument to a function, then the Suppress option only works at the function level (which would also suppress other name reference violations that might exist within that function that has had styling conventions suppressed)

您还可以选择完全关闭 PEP8编码样式违规(下方的复选框),或管理明确的忽略错误手动。截图如下:

You do also have the option of switching off "PEP8 coding style violations" altogether (tick box below), or managing explicit "Ignore Errors" manually. Screenshot given below:

一般来说,你应该或许会质疑为什么要压制PEP8指南。但是,有时似乎有必要,例如使用pytest模块,有必要隐藏PEP8检查所抱怨的变量等,在这种情况下,PyCharm中的这个功能非常有用。

In general, 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.

这篇关于Pycharm的代码样式检查:忽略/关闭特定规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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