Can I get PyCharm to suppress a particular warning on a single line?

PythonPycharmCompiler WarningsSuppress Warnings

Python Problem Overview


PyCharm provides some helpful warnings on code style, conventions and logical gotchas. It also provides a notification if I try to commit code with warnings (or errors).

Sometimes I consciously ignore these warnings for particular lines of code (for various reasons, typically to account for implementation details of third-party libraries). I want to suppress the warning, but just for that line (if the warning crops up on a different line where I'm not being deliberate, I want to know about it!)

How can I do that in PyCharm? (Following a universal Python convention strongly preferable.)

Python Solutions


Solution 1 - Python

To suppress PyCharm code inspections for a particular line of code you can use the following construct:

# noinspection INSPECTION_NAME
your_line_of_code_to_suppress

where the name of the inspection (INSPECTION_NAME above) you can take from the list of inspection names (they are pretty descriptive).

To suppress pylint command line messages explicitly you have to use different comments/commands, as described here (pylint error names).

Solution 2 - Python

Essentially, for the file in which you want to suppress the warning, run it through code inspection, post which PyCharm will give you warnings in that particular file. You can then review the warnings and tell PyCharm to suppress warning for a particular statement.

Code Inspection can be accessed from Code-->Inspect Code menu from where you can select the file that you want to inspect.

Below is an image that shows how to do it for an image, after running code via CodeInspection Code Inspection Output

Link for more details around suppressing warnings: https://www.jetbrains.com/help/pycharm/2016.1/suppressing-inspections.html#1

Solution 3 - Python

To just suppress the warning in the editor, there's also a lazy suppression option which is to use the comment noqa on the same line, such as:

from application import routes  # noqa

Here's a before and after image using this comment:

Before

Before using the comment

After

After using the comment


Source:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlofidevopsView Question on Stackoverflow
Solution 1 - PythonsophrosView Answer on Stackoverflow
Solution 2 - PythonprabodhprakashView Answer on Stackoverflow
Solution 3 - PythonBill WallisView Answer on Stackoverflow