Pycharm's code style inspection: ignore/switch off specific rules

Krzysztof Stanisławek picture Krzysztof Stanisławek · Feb 10, 2015 · Viewed 31.5k times · Source

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

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

Answer

arcseldon picture arcseldon · Nov 30, 2015

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:

enter image description here

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

enter image description here

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).

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:

enter image description here

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.