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

查看:58
本文介绍了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 look at the screenshot below:

当您选择Suppress"选项时,它会添加如下截图所示的注释:

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

可以在语句或函数/方法级别进行抑制.如果尝试抑制函数的参数,则抑制仅在函数级别起作用(这意味着它还会抑制该函数中可能存在的其他名称引用违规).

Suppressing can be done at the statement, or function/method, levels. If trying to suppress an argument to a function, the suppression only works at the function level (meaning it also suppresses other name reference violations that might exist within that function).

您还可以选择完全关闭PEP8 编码风格违规"(通过勾选下面显示的框),或手动明确管理忽略错误".截图如下:

You also have the option of switching off "PEP8 coding style violations" altogether (by ticking the box shown below), or explicitly managing "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 when using the pytest module, it is necessary to shadow variables, etc, which the PEP8 Inspection complains about in. In such cases, this feature in PyCharm is very helpful.

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

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