Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 962
lofidevops Avatar asked Oct 04 '16 08:10

lofidevops


People also ask

How do I ignore a specific warning in Python?

Use the filterwarnings() Function to Suppress Warnings in Python. The warnings module handles warnings in Python. We can show warnings raised by the user with the warn() function. We can use the filterwarnings() function to perform actions on specific warnings.

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


1 Answers

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

like image 99
sophros Avatar answered Oct 01 '22 02:10

sophros