How do I tell PyLint "it's a variable, not a constant" to stop message C0103?

Solution 1:

# 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 it is true that pylint interprets all module-level variables as being 'constants'.

newer versions of pylint will take this line instead

# pylint: disable=C0103

Solution 2:

You can also specify a comma separated list of "good-names" that are always allowed in your pylintrc, eg:

[BASIC]
good-names=_log

Solution 3:

Seems to me a bit of refactor might help. Pylint in looking at this as a module, so it would be reasonable not to expect to see variables at this level. Conversely it doesn't complain about vars in classes or functions. The following paradigm seems quite common and solves the issue:

def main():
    '''Entry point if called as an executable'''
    _log = MyLog()  # . . .

if __name__ == '__main__':
    main()

This has the benefit that if you have some useful classes, I can import them without running your main. The __name__ is that of the module so the "if" fails.