Search code examples
pythonpycharmcompiler-warningssuppress-warnings

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


Solution

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