37

I installed PyCharm and enabled PEP8 checks in Inspections. If I write:

def func(argOne):
    print(argOne)

The IDE shows me this warning:

Argument name should be lowercase

There is no option to ignore only this inspection. I can't find such error number to ignore in PEP8. The naming inspections are here. How to ignore only some of them?

I need this because the current project coding guidelines must be kept. It's too hard to change the guidelines of the whole project.

I need to disable only some naming inspections. Not all like by "Settings"-> "Editor"-> "Inspections"->"PEP8 coding style violation". E.g. class names should be still inspected with PEP8 but function argument names should not.

2
  • 6
    The best way is to name things correctly. Commented Oct 15, 2015 at 16:03
  • 23
    @MorganThrapp that's not "correct" or "incorrect"; it's a matter of style. Not all of us only write in Python. I prefer descriptive names and find underscores to be painful. However, there are a lot of PEP-8 guidelines I follow. I'd prefer to only disable a couple of PEP-8 warnings. I feel like PyCharm used to support this...
    – Will
    Commented Mar 9, 2016 at 19:29

5 Answers 5

50

Since PyCharm 2.7 you can hover over the inspected code and use the light bulb to Ignore errors like this.

highlighted code ignore errors

Further more you can manage the ignored errors at Settings > Editor > Inspections > Python > PEP 8 naming convention violation > Ignored errors

pep8 naming convention settings

Tested in PyCharm Community Edition 2016.3.2

Edit:

To remove the modification later on you can use filter button to Show Only Modified Inspections and delete the Ignored errors with remove button

inspection filter

Tested in PyCharm Community Edition 2017.2.3

7
  • looks like its not a solution, since we need to change not naming, but coding style violation, did you tried it with the example in the question?
    – ya_dimon
    Commented Jan 24, 2017 at 14:46
  • Argument name should be lowercase belongs to naming conventions (PEP N806) which is why I have decided to show a screenshot with the naming conventions. As you can see on the last screenshot, there are coding style violations above the naming convention violations as well. The other screenshots are from the linked jetbrains article and show coding style violations. The process of ignoring coding style and naming convention violations is the same.
    – Cani
    Commented Jan 25, 2017 at 11:28
  • e.g. class names should be still inspected with PEP8, and function argument names not if you get it, this could be an answer. The screenshots are 2013, question 2015, that is why i m sceptical (i dont use PyCharm right now)
    – ya_dimon
    Commented Jan 25, 2017 at 12:29
  • I used the first two screenshots from the article because ignoring errors in PyCharm 2016 didn't change. As you can see in the last link argument names, function names, class names and variable names in functions have different codes so it is possible to ignore argument names only (N803).
    – Cani
    Commented Jan 25, 2017 at 14:31
  • just downloaded and tested, looks like it works :) At least with 2016.3.2
    – ya_dimon
    Commented Jan 25, 2017 at 16:52
22

Using PyCharm 5 (community edition), you can do the following. Code -> Inspect Code. Then select the required inspection error, and click on the "Suppress" option on right hand side. Please see screenshot below:

PyCharm 5 Inspection

Once you have done this, it adds a comment as shown in screenshot below:

Result

As already mentioned in other comments, you should perhaps question why you are suppressing PEP8 guidelines. However, sometimes it appears necessary, for instance using the pytest module it is necessary to shadow variables etc which PEP8 Inspection complains about in which case this feature in PyCharm is very helpful.

7
  • what about other namings? I want do disable e.g. only argument names.
    – ya_dimon
    Commented Nov 29, 2015 at 20:53
  • @ya_dimon - you asked a specific question providing a specific example, and I have provided an answer that addresses what has been asked. Am hopeful you might agree it is the correct answer ;) Please can you update your question with an example of what you are now asking, together with a reason why you wish to do so? Recommend adhering to PEP8 guidelines wherever possible - what is your scenario? Also, feel free to play around with PyCharm 5 Community Edition (free) and see if you can't get the behaviour you seek.
    – arcseldon
    Commented Nov 30, 2015 at 11:44
  • @ya_dimon - btw, a quick check earlier indicated that whilst you can suppress for individual statements within a function, you cannot do so for just an argument - this makes sense in that the function argument has function scope, and since it is declared within the params of the function definition itself, the option avaiable is function level suppression.
    – arcseldon
    Commented Nov 30, 2015 at 14:58
  • i updated the question to make more sure, what is the problem. It is about "how to disable only part of all PEP8 naming inspections" in PyCharm
    – ya_dimon
    Commented Dec 4, 2015 at 14:04
  • 2
    I do this differently, i use PyCharm as well, but i configure PEP8, Pylint and flake in their respective project configuration files: setup.cfg, pylint.ini and inline with #noqa or # pylint: disable notation. Then in PyCharm, i simply configure flake8/pep8/pylint to run as external tools. The benefit is that your collaborators using vim/emacs and your CI server will get identical results.
    – kert
    Commented Feb 9, 2016 at 8:32
3

Argh! This was frustrating to me as well.

It is the only warning I disagree with. Anyways, you can fix it by flicking this checkbox in the image.

How to turn off the warnings against camelCase

2
  • 1
    I agree with the sentiment, camelcase allows multiple words to be used in identifiers increasing readability by allowing more descriptive identifiers. Personally i can tell the difference between a function, an object and a variable in python without the need for a naming standard.
    – Duane
    Commented Sep 16, 2017 at 17:36
  • If you want multiple words in an identifier while following pep8, use underscores, as is expected in snake_case Commented Jan 7 at 2:43
1

As it stands right now the only way to prevent that specific naming convention from pep8 is to disable it altogether through Settings> Inspections > Python, or simply leave as is.

5
  • 3
    i need to disable only one check, other should be still here. Question updated.
    – ya_dimon
    Commented Oct 15, 2015 at 16:46
  • 1
    Nowhere in the documentation that's mentioned. You might need to look into using pypi.python.org/pypi/pep8-naming Other than that either ignore the warning, disable all pep8, or simply name it right.
    – Leb
    Commented Oct 15, 2015 at 17:02
  • ok. there is no way to do it. Update your answer and i ll accept it.
    – ya_dimon
    Commented Oct 15, 2015 at 17:29
  • I edited and kept the option to disable altogether if someone might be interested.
    – Leb
    Commented Oct 15, 2015 at 17:35
  • As of PyCharm 5 (not unsure of previous versions), this is actually possible. I shall post an answer below to explain the required steps.
    – arcseldon
    Commented Nov 28, 2015 at 11:41
1

Updating the answer by @arcseldon.

Using PyCharm 2024, you can do the following. Click Problems (Alt + 6), then select the line with the inspection you want to disable, then in the Bulb menu, press submenu button, and select Suppress for a function.

PyCharm inspection tool menu

Once you have done this, it adds a comment as shown in screenshot below:

PyCharm inspection ignoring comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.