Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pylint assume module-level variables are constants?

In the answer to how to stop Pylint message C0103, @ChristopheD accurately mentioned that "pylint interprets all module-level variables as being 'constants'."

I like Pylint, and suppose that the authors have code-quality-encouraging reasons for its default behavior. So, can anyone tell me: why does pylint interpret all module-level variables as being 'constants'?

Is this perhaps pylint's way of highlighting implicit global variables, which are considered bad?

like image 729
talkaboutquality Avatar asked Sep 16 '15 18:09

talkaboutquality


1 Answers

In answer Why is Global State so Evil? it is clarified that using global variables adds complexity and uncertainty since you don't know who accesses this global variable.

As stated in the answer it would also make your code less (unit)testable.

Declaring it as a constant is in linting terms more acceptable because when the variable/constant doesnt change you wouldn't have this uncertainty.

like image 166
studioj Avatar answered Nov 23 '22 10:11

studioj