How to disable special naming convention inspection of PEP 8 in PyCharm?
Asked Answered
C

5

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.

Clearway answered 15/10, 2015 at 16:0 Comment(2)
The best way is to name things correctly.Implicatory
@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...Joanajoane
L
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

Lazurite answered 23/1, 2017 at 10:55 Comment(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?Clearway
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.Lazurite
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)Clearway
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).Lazurite
just downloaded and tested, looks like it works :) At least with 2016.3.2Clearway
I would like to ignore some warnings in the beginning, but later on I might want to fix these, too. Is there an easy way to reset to default configuration?Analphabetic
Use the filter button next to the inspection search field to Show Only Modified Inspections. Added a screenshot to the answer.Lazurite
S
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.

Styrax answered 28/11, 2015 at 11:48 Comment(7)
what about other namings? I want do disable e.g. only argument names.Clearway
@Clearway - 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.Styrax
@Clearway - 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.Styrax
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 PyCharmClearway
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.Zimmerman
"why you are suppressing PEP8 guidelines" Maybe because PEP 8 is tripe. If you want to require something, then /require/ it (on the interpreter level) [and then you will have the additional privilege of me no longer using your stupid damn language].Equities
Can I do this for an entire file? I know they just added suppression at the file level for PHPStormLovel
R
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

Retrogressive answered 22/1, 2017 at 1:2 Comment(2)
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.Encratis
If you want multiple words in an identifier while following pep8, use underscores, as is expected in snake_caseVespucci
A
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.

Agna answered 15/10, 2015 at 16:9 Comment(5)
i need to disable only one check, other should be still here. Question updated.Clearway
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.Agna
ok. there is no way to do it. Update your answer and i ll accept it.Clearway
I edited and kept the option to disable altogether if someone might be interested.Agna
As of PyCharm 5 (not unsure of previous versions), this is actually possible. I shall post an answer below to explain the required steps.Styrax
M
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

Mollee answered 16/6 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.