Dismiss PyCharm code inspection warning for particular line of code
Asked Answered
A

2

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?

Astaire answered 26/12, 2013 at 15:29 Comment(2)
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: postimg.org/image/o4xvaapv3Aurita
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.Monkfish
A
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

Aurita answered 27/12, 2013 at 15:22 Comment(1)
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.Honeysucker
R
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.

Resolved answered 10/10, 2022 at 16:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.