Pylint invalid function name

筅森魡賤 提交于 2020-01-02 01:59:40

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/48507986/pylint-invalid-function-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!