9

I'm running Pylint 1.7.2 with Python 3.6.2. Pylint is showing the following error:

Invalid function name "create_maximization_option_dataframe" (invalid-name)

I define a function like so in my code:

def create_maximization_option_dataframe(file_name):

The PEP8 style guide basically just says:

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

As far as I'm aware I'm following all the formatting rules for a function name. Does Pylint have some built-in maximum function name length rule that I'm not aware of? I can ignore the Pylint error easily enough but I want to understand why this is happening first.

Shakes
  • 531
  • 1
  • 5
  • 16

2 Answers2

13

Make a config file by doing pylint pylint --generate-rcfile. The scope of that depends where you put it. Quoting https://docs.pylint.org/en/1.6.0/run.html

  1. pylintrc in the current working directory
  2. .pylintrc in the current working directory
  3. If the current working directory is in a Python module, Pylint searches up the hierarchy of Python modules until it finds a pylintrc file. This allows you to specify coding standards on a module-by-module basis. Of course, a directory is judged to be a Python module if it contains an init.py file.

  4. The file named by environment variable PYLINTRC

  5. if you have a home directory which isn’t /root: .pylintrc in your home directory
    .config/pylintrc in your home directory

  6. /etc/pylintrc

Sounds like you need option 5 or 6.

In the pylintrc, find this bit

# Regular expression matching correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$

Change that 30 near the end to 40 or so.

  • I tried adding an empty pylintrc file to the project. But I get an error: configparser.MissingSectionHeaderError: File contains no section headers. Please can you add the header info to your answer? – variable Nov 29 '19 at 05:42
7

According to PyLint documentation, a function name must have from 2 to 30 characters. Yours has 36.

Just a nice guy
  • 549
  • 3
  • 19
DYZ
  • 55,249
  • 10
  • 64
  • 93
  • That documentation states: "Options can be used to override the default regular expression associated to each type." How can I globally override the function name length limit imposed by PyLint? – Shakes Jan 29 '18 at 19:09
  • 2
    Check PyLint documentation, it has it all: https://pylint.readthedocs.io/en/latest/user_guide/options.html – DYZ Jan 29 '18 at 19:13
  • 2
    Actually, I think it's 3 to 31 characters: `[a-z_][a-z0-9_]{2,30}$`. If you wanted 2 to 30, that would be `[a-z_][a-z0-9_]{1,29}$` – Martim Nov 18 '19 at 23:44