Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 618
Krzysztof Stanisławek Avatar asked Feb 10 '15 09:02

Krzysztof Stanisławek


People also ask

How do I ignore a warning in PyCharm?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Inspections. Locate the inspection you want to disable, and clear the checkbox next to it. Apply the changes and close the dialog.

How do I turn off suggestions in PyCharm?

Go to File > Settings (or Ctrl + Alt + S ) > [IDE Settings] > Editor > Code Completion. The "Autopopup code completion" setting will determine if the popup opens automatically. Below it, the "Insert selected variant by typing dot, space, etc." is likely the setting you want to turn off.

How do you get rid of weak warnings in PyCharm?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Inspections. Select the profile in which you want to create a new severity level. Click any inspection and select Edit severities from the list of severity levels.

How to suppress an inspection error in PyCharm?

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:

Where does PyCharm store the default code style scheme?

These settings are stored in the codestyles folder under the PyCharm configuration directory and are not shared through VCS. If you want to use the project code style scheme as your default scheme, you can copy it to the IDE level.

How do I view all detected code problems in PyCharm?

The reported problems are grouped by type, so you can evaluate and suppress all inspections of the same type. By default, PyCharm highlights all detected code problems. Hover the mouse over the widget in top-right corner of the editor and select another level from the Highlight list: None: turn highlighting off.

What is the difference between suppress and ignore in PyCharm?

In such cases, this feature in PyCharm is very helpful. 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.


2 Answers

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.

like image 88
arcseldon Avatar answered Sep 21 '22 13:09

arcseldon


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

like image 40
fantabolous Avatar answered Sep 18 '22 13:09

fantabolous