PyLint 希望将变量命名为常量 [C0103]

PyLint wants a variable to be named as a constant [C0103]

为什么 PyLint 要求变量具有 UPPER_CASE 命名,就像它是常量一样?

"""Stack reproducible example."""

some_list = ['foo', 'bar']
for i in some_list:
    counter = 3
    while counter != 0:
        print("Value of 'counter': " + str(counter))
        counter -= 1

这给出了 linting 错误:

# C0103: Constant name "counter" doesn't conform to UPPER_CASE naming style (invalid-name)

然而,与阿伏加德罗常数 Pi 或真空中的声速不同,counter 的值会发生变化,这肯定会使它成为 'variable'?

我已经阅读了关于 C0103 的页面,但我显然不明白。

是否将 for 循环视为一次性函数,从而改变约定,例如 this question

查看 2 个解决方案here

  1. This is not a false positive. Pylint expects all variables at the module level to be upper case. This behaviour can be configured by passing an updated const-rgx setting in the configuration file.

  2. Just want to add that another solution is to add logger to good-names setting in the configuration file.