我如何告诉 PyLint “它是一个变量,而不是一个常量"?停止消息 C0103? [英] How do I tell PyLint "it's a variable, not a constant" to stop message C0103?

查看:23
本文介绍了我如何告诉 PyLint “它是一个变量,而不是一个常量"?停止消息 C0103?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Python 2.6 程序中有一个名为_log"的模块级变量,PyLint 抱怨:

I have a module-level variable in my Python 2.6 program named "_log", which PyLint complains about:

C0103: Invalid name "_log" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)

阅读这个答案后,我明白为什么要这样做:它认为变量是一个常量并应用常量正则表达式.但是,我不同意:我认为这是一个变量.我如何告诉 PyLint,所以它不会抱怨?PyLint 如何确定它是变量还是常量——它是否只是将所有模块级变量都视为常量?

Having read this answer I understand why it's doing this: it thinks the variable is a constant and applies the constant regex. However, I beg to differ: I think it's a variable. How do I tell PyLint that, so it doesn't complain? How does PyLint determine whether it's a variable or a constant - does it just treat all module-level variables as constants?

推荐答案

# pylint: disable-msg=C0103

将其放在您希望忽略这些警告的范围内.您还可以将上述内容作为行尾注释,以仅针对该行代码禁用该消息.

Put it in the scope where you want these warnings to be ignored. You can also make the above an end-of-line comment, to disable the message only for that line of code.

IIRC 确实 pylint 将所有模块级变量解释为常量".

IIRC it is true that pylint interprets all module-level variables as being 'constants'.

较新版本的 pylint 将采用这一行

newer versions of pylint will take this line instead

# pylint: disable=C0103

这篇关于我如何告诉 PyLint “它是一个变量,而不是一个常量"?停止消息 C0103?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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