In this section:
- Suppressing inspections in the editor
- Suppressing inspections from the Inspection tool window
For some reasons, you may want to partly disable a specific inspection, i.e. ignore some code issues while continuing to detect the other issues with this inspection.
For example, PyCharm considers some code to be "dead", and you can see that it is true. The inspection is helpful and you do not want to disable it. However, you may want to use this code later and do not want it to be highlighted in the editor or appear in the issue reports.
To do so, PyCharm allows you to suppress certain inspections for a specific statement, function/method, tag or file. You can do it either in the editor, using the suggestion list or in the Inspection tool window when analysing inspection results.
Let's summarize the difference between suppressing and disabling code inspections:
When suppressing an inspection, PyCharm inserts a special comment that tells the code analysis engine to ignore the issues found by this inspection in the specific piece of code.
When disabling an inspection, you just turn it off so the code analysis engine just ignores the code issues found by this inspection.
Some code inspections (e.g. those detecting errors) cannot be suppressed.
Suppressing inspections in the editor
- Set the cursor to the highlighted code issue in the editor.
- Press Alt+Enter, or click the light bulb icon to expand the suggestion list.
- Depending on the issue, you will see either quick-fixes related to the inspection ot the Inspection "<inspection name>" options item.
Use the up/down arrow keys to select this item and then press the right arrow key
or just click the right arrow
next to this item.
Pressing the left arrow key, or Escape hides the suggestion list.
- In the inspection options list, select the desired suppress action: The inspection will be suppressed with special comments in the corresponding piece of code.
Suppressing inspections from the inspection tool window
- After running code analysis, select a code issue, for which you want to suppress the inspection, in the Inspection tool window.
- Click on the toolbar of the Inspection tool window, or just right-click the selected inspection.
- Choose the desired suppress action. For example: The inspection will be suppressed with special comments in the corresponding piece of code.