15

PyCharm's code inspection is a useful tool, but sometimes it gets things wrong. I know you can disable whole classes of warnings via settings, but what if you just want to dismiss a specific instance of a warning at a particular line?

sophros
  • 14,672
  • 11
  • 46
  • 75
Ghopper21
  • 10,287
  • 10
  • 63
  • 92
  • 1
    **Not sure if it actually works like this in PyCharm** (not using this particular JetBrains IDE) but please try: 1) `Alt+Enter` while cursor standing on problematic place; 2) Select appropriate entry from appeared popup menu; 3) Expand submenu (click on small triangle on the right side .. or just `arrow right` key on keyboard; 4) Choose `Suppress for statement` from there. This is how it looks in **PhpStorm**: http://postimg.org/image/o4xvaapv3/ – LazyOne Dec 27 '13 at 12:28
  • An example of pyCharm getting it wrong is when you're using class properties and it hollars at you for not defining attributes outside of init, i.e. in init you have `self.my_property` and in the setter you do `self._my_property` By the way, it's just `option+enter` if you're on a mac. – RYS Sep 03 '15 at 10:53

2 Answers2

16

1. Alt + Enter while cursor standing on problematic place.

2. Select appropriate entry from appeared popup menu.

3. Expand submenu (click on small triangle on the right side .. or just press arrow right key on keyboard.

4. Choose "Suppress for statement" from there.

In the end special comment will be added just before that line that would temporarily turn off that specific inspection for next statement.

This is how it looks in PhpStorm (sorry, I'm not PyCharm or Python user):

enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • 3
    Emphasis on typing **right-arrow**. In PyCharm 4.5 clicking the small triangle does not work to install a `# noinspection` comment. Instead it engages the default solution. – Bob Stein May 15 '15 at 18:00
0

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

Source

Here is duplicate question that has more answers.

Anton Samokat
  • 542
  • 1
  • 6
  • 15