3

When running Pylint on my file I am getting the following message.

refactor (R0915, too-many-statements, function) Too many statements (95/50)

I want to set the number of statements a function can have to 100 instead of 50 in order avoid the above message from Pylint.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Does this answer your question? [Can Pylint error checking be customized?](https://stackoverflow.com/questions/10138917/can-pylint-error-checking-be-customized) – Kris Mar 18 '20 at 08:54
  • The answer has the options to specify custom configs too. – Kris Mar 18 '20 at 10:50
  • I don't want to disable the check. I want to modify the statement check from 50 to 100. I had modified the max-line-length from 100 to 120. eg: default: max-line-length = 100. modified: max-line-length = 100 = 120. Is there any way like that to replace the statement check from 50 statements per function to 100 statements allowed per function? – Raswanth Anitha Mar 18 '20 at 11:45
  • That link tells about regex, but I am not able to find how to change 50 to 100 in too-many-statements. – Raswanth Anitha Mar 18 '20 at 15:11

1 Answers1

6

Pylint works based on configured settings which are default PEP 8 standards. Now, if customizing them is good or bad can be taken for another discussion, as they are kept like that for a reason. For example, if you have a method with more than 50 lines of code, it simply means that you are increasing the cyclomatic-cognitive complexities as well as making it difficult to unit test and get coverage.

OK, arguments aside, I think the following approach can help you customize the linting rule.

Go to your Python site-packages directory (it might be inside the Python installation Libs folder or in your virtual environment.

For example, D:\Python37\Lib\site-packages

Open a command line here, and navigate to the Pylint directory. Execute the configuration generator like

pylint --generate-rcfile > custom_standard.rc

Now you will have a file named custom_standard.rc in the folder. Let’s copy it to some place around your project, say, D:\lint_config\custom_standard.rc.

Open the configuration file. You can see a setting for most of the rules. Now, for your question of number of statements inside a method, find the setting called

max-statements=50

Change it to:

max-statements=100

Save the configuration file. Now when you run the Pylint executable, use the option --rcfile to specify your custom configuration:

pylint --rcfile=D:\lint_config\custom_standard.rc prject_dir

If you want to integrate this with your IDE like PyCharm there are plugins which allows configuring the same.

But again!, it is not a good decision to change the PEP 8 :-)

Andrey Starodubtsev
  • 5,139
  • 3
  • 32
  • 46
Kris
  • 8,680
  • 4
  • 39
  • 67