Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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’?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading