Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constants naming rules #49

Open
sobolevn opened this issue Feb 3, 2018 · 8 comments
Open

Add constants naming rules #49

sobolevn opened this issue Feb 3, 2018 · 8 comments

Comments

@sobolevn
Copy link
Member

sobolevn commented Feb 3, 2018

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)

@5j9
Copy link
Contributor

5j9 commented May 25, 2018

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.

@sobolevn
Copy link
Member Author

sobolevn commented May 25, 2018

@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.

@5j9
Copy link
Contributor

5j9 commented May 25, 2018

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.

@master468
Copy link

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?

@noorul
Copy link

noorul commented Nov 14, 2021

Any update on this? Is anyone using any other plugin other than pylint for this?

@sobolevn
Copy link
Member Author

@noorul
Copy link

noorul commented Nov 14, 2021

I tried adding this, but it takes too much time to complete the scan.

@ipadla
Copy link

ipadla commented Nov 30, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants