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

Expand variable name type to include non-constant, module-level variables #4606

Closed
mdepp opened this issue Jun 22, 2021 · 3 comments
Closed
Assignees
Labels
Duplicate 🐫 Duplicate of an already existing issue False Negative 🦋 No message is emitted but something is wrong with the code Regression

Comments

@mdepp
Copy link

mdepp commented Jun 22, 2021

Is your feature request related to a problem? Please describe

Naming style of module-level non-constant variables is not enforced. For example,

helloWorld = True  # should be HELLO_WORLD; caught as `invalid-name` message
goodbyeWorld = {}  # should be goodbye_world; not caught by pylint

My best guess for the reason is that non-constant module-level variables do not fall into any name type. Prior to pylint 2.5.0 they counted as const. This was fixed in 3422e4a, but now there are no naming style checks at all for these variables.

Describe the solution you'd like

Expand the variable name type to include non-constant module-level variables. Alternatively, define a new name type specifically for non-constant, module-level variables.

Additional context

@Pierre-Sassoulas Pierre-Sassoulas added Regression False Negative 🦋 No message is emitted but something is wrong with the code labels Jun 22, 2021
@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Jun 22, 2021

The fix is "easy", I have something locally. But there would be false positive as soon as pylint make a mistake on the inference of a constant. Also it broke 53 tests in the test suite most of them functional, For example:

TESTLIST = [1, 2, 3] # now raise [invalid-name] should be test_list
TESTTUPLE = (1, 2, 3)  # now raise  [invalid-name] should be test_tuple
TESTSTR = '123' # constant, so an OK name

Or :

j = 4; LAMB = lambda x: x+j  #  now raise [invalid-name] should be lamb ?

FUNC4 = lambda a, b: a != b  #  now raise [invalid-name] should be func_foor ?

I use constant that are mutable sometime, and variable that are immutable. So I don't know, about this one. Maybe a test that this is UPPER_CASE or snake_case but not something else ? In fact for logger vs LOGGERI've seen both usage in big python code base, so having a warning for this seem opinionated.

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jun 22, 2021
@mdepp
Copy link
Author

mdepp commented Jun 22, 2021

Checking for either UPPER_CASE or snake_case makes sense to me. Really I just want to prevent mixedCase from showing up in globals... Maybe the best solution is to create a new name type then.

@Pierre-Sassoulas
Copy link
Member

Closing as a duplicate of #3585

@Pierre-Sassoulas Pierre-Sassoulas added the Duplicate 🐫 Duplicate of an already existing issue label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue False Negative 🦋 No message is emitted but something is wrong with the code Regression
Projects
None yet
Development

No branches or pull requests

2 participants