-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
C: invalid-nameFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation
Milestone
Description
Bug description
The patch notes for 4.0.0 show that invalid-name now tries to figure out if a module-level variable is constant or not. It shows that the following would be treated as a variable:
LIMIT = 500 # [invalid-name]
if sometimes:
LIMIT = 1 # [invalid-name]The release notes state (correctly) that the following should prevent the constant from being treated as a variable:
if sometimes:
LIMIT = 1
else:
LIMIT = 500 # exclusive assignment: uses const regex, no warningHowever, the following gives a false-positive invalid-name alert:
if sometimes == 1:
LIMIT = 1 # [invalid-name]
elif sometimes == 2:
LIMIT = 2 # [invalid-name]
else:
LIMIT = 500 # [invalid-name]Configuration
Command used
python3 -m pylint test3.pyPylint output
test3.txt:6:3: C0103: Variable name "LIMIT" doesn't conform to snake_case naming style (invalid-name)
test3.txt:8:3: C0103: Variable name "LIMIT" doesn't conform to snake_case naming style (invalid-name)
test3.txt:10:3: C0103: Variable name "LIMIT" doesn't conform to snake_case naming style (invalid-name)Expected behavior
LIMIT is treated as a constant and no invalid-name is raised.
Pylint version
pylint 4.0.0
astroid 4.0.1
Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0]OS / Environment
Ubuntu 24.04
Additional dependencies
Metadata
Metadata
Assignees
Labels
C: invalid-nameFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation