Add constants naming rules
pep8 implies that constants are named in UPPER_CASE: https://www.python.org/dev/peps/pep-0008/#constants
Right now this code is considered valid:
# Module-level variable:
delta = 10
However, it is not valid. This one is:
# Module-level variable:
DELTA = 10
pylint has checks for it: C: 8, 0: Constant name "delta" doesn't conform to UPPER_CASE naming style (invalid-name)
I'm curious to know how pylint detects constants. Note that if a constant literal (10) is assigned to a variable (delta), that's not enough evidence to call that variable a constant. Some other value can be assigned to the same variable later in the code...
I'd say doable, but requires a more in depth introspection.
@5j9 I would say that constant is a misleading name.
'Module level variable' is better. And by convention we name these variables as UPPER_CASE.
Ah, in that case we do not agree on what is considered a constant. I've always thought of them having a constant value, i.e. I never use UPPER_CASE for a for-loop variable, even if it is defined at the module level. Same for any global variable that gets reassigned or mutated during the execution of the code in that module.
I'm looking at the differences between pylint and pep8-naming (through flake8) and came across this page. Has there been any development on this in the past year?
Any update on this? Is anyone using any other plugin other than pylint for this?
I use wemake-python-styleguide that has this rule: https://wemake-python-stylegui.de/en/latest/pages/usage/violations/naming.html#global-module-level-variables
I tried adding this, but it takes too much time to complete the scan.
I made a small plugin for flake8 https://pypi.org/project/flake8-class-constants/ It's dirty, without tests, but it seems to work on small projects