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

32,274

Solution 1

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.

Solution 2

If you're ok to ignore all matching issues, you can just press Alt-Enter (or click on the lightbulb) and choose "Disable Inspection". Saves you going into the settings and trying to figure out the inspection rule that matches.

From http://iambigblind.blogspot.jp/2013/02/configuring-pep8py-support-in-pycharm-27.html

Solution 3

@Krzysztof Stanisławek, function is different as Pycharm follows the PEP8 coding style, so it is recommended that there is no whitespace between the function variables and ":", if you don't want this, you can disable it by

"Settings"-> "Editor"-> "Inspections"->"PEP8 coding style violation"

However, this is not recommended.

Solution 4

I got the same issue, and the neat solution has been pointed by @fantabolous, from configuring PEP8.py support in PyCharm 2.7

Example before
Code with multiple space warning

Adding the error code either manually or with "Alt+Enter" on error highlight
The error code can be found here
enter image description here

After the changes
enter image description here

It's great to select precisely some rules instead of disabling all warning from PEP8. Thanks to the previous comments.

Share:
32,274
Krzysztof Stanisławek
Author by

Krzysztof Stanisławek

Updated on December 17, 2020

Comments

  • Krzysztof Stanisławek
    Krzysztof Stanisławek over 3 years

    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?

  • Krzysztof Stanisławek
    Krzysztof Stanisławek about 9 years
    I forgot to mention: option "before ":"" affects also function definitions, e.g. def foo() :.
  • Krzysztof Stanisławek
    Krzysztof Stanisławek about 9 years
    More of a problem is auto-formatter. I can either reformat my code to {a: b, c: d} instead of preferred {a : b, c : d}, or to def foo(self) :. The problem is that formatter treats : the same in both cases, there are no separate options for these cases. I don't think there is a way (it looks like Pycharm is lacking feature I need), so I think I'll either persuade my teammates to change our dicts style to {a: b}, or use simple regex to format : at the ends of the methods parentheses.
  • Phrogz
    Phrogz over 7 years
    Note that Suppress modifies the source code (so that no other developers on your project see the warning) while Ignore turns them off just for your machine (local Inspections Profile); other developers with different profiles will still see the warning.
  • Rotareti
    Rotareti over 7 years
    If you want to deactivate certain errors explicitly like in the last screenshot. Here is a list of PEP8 error codes: pep8.readthedocs.io/en/release-1.7.x/intro.html#error-codes
  • ThatAintWorking
    ThatAintWorking over 7 years
    What do you actually put in the Ignore Errors list? I can't find an example.
  • Rotareti
    Rotareti about 7 years
    @ThatAintWorking Check out the link that I posted. There is a list with error IDs. Just add the ones you don't like to the box. E.g. E701
  • Dilum Ranatunga
    Dilum Ranatunga over 6 years
    Found this about disabling specific PEP8 guidelines: iambigblind.blogspot.de/2013/02/…