Solebay Sharp
Solebay Sharp

Reputation: 533

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

Why does PyLint require a variable to have UPPER_CASE naming as though it is a constant?

"""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

This gives the linting error of:

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

However unlike Avogadro's Constant, Pi, or the speed of sound in a vaccum, the value of counter changes which surely must render it a 'variable'?

I have read the page regarding C0103 but I obviously don't understand something.

Is a for-loop considered a single-use function thus altering convention such as in this question?

Upvotes: 2

Views: 2250

Answers (1)

zvi
zvi

Reputation: 4676

See 2 solutions 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.

Upvotes: 5

Related Questions