Pylint 无效的函数名 [英] Pylint invalid function name

查看:71
本文介绍了Pylint 无效的函数名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 3.6.2 运行 Pylint 1.7.2.Pylint 显示以下错误:

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):

PEP8 风格指南基本上只是说:

The PEP8 style guide basically just says:

函数名称应为小写,单词之间用下划线分隔以提高可读性.

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

据我所知,我遵循函数名称的所有格式规则.Pylint 是否有一些我不知道的内置最大函数名称长度规则?我可以很容易地忽略 Pylint 错误,但我想了解为什么会首先发生这种情况.

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.

推荐答案

通过执行 pylint pylint --generate-rcfile 来制作配置文件.范围取决于你把它放在哪里.引用 https://docs.pylint.org/en/1.6.0/run.html

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
  2. .pylintrc 中的当前工作目录
  3. 如果当前工作目录在Python 模块,Pylint 向上搜索 Python 模块的层次结构直到它找到一个 pylintrc 文件.这允许您指定编码基于模块的标准.当然,目录是如果包含 init.py 文件,则判断为 Python 模块.

  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.

由环境变量PYLINTRC命名的文件

The file named by environment variable PYLINTRC

如果你有家不是/root 的目录:您的主目录中的 .pylintrc
.config/pylintrc 在您的主目录中

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

/etc/pylintrc

/etc/pylintrc

听起来您需要选项 5 或 6.

Sounds like you need option 5 or 6.

在pylintrc中,找到这个位

In the pylintrc, find this bit

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

将接近尾声的 30 改为 40 左右.

Change that 30 near the end to 40 or so.

这篇关于Pylint 无效的函数名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆