-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Needs triage 📥Just created, needs acknowledgment, triage, and proper labellingJust created, needs acknowledgment, triage, and proper labelling
Description
Bug description
Here's a problematic code according to the pylint.extensions.magic_value checker.
ll = ["test"]
if "test" in ll:
raise ValueError("test in list")Which raises the following warning:
test.py:4:11: R2004: Consider using a named constant or an enum instead of ''test''. (magic-value-comparison)
Fixing it using the suggestion from documentation like so raises a new warning from the pylint.extensions.code_style checker this time:
ll = ["test"]
TEST = "test"
if TEST in ll:
raise ValueError("test in list")Warning:
test.py:5:3: R6103: Use 'if (TEST := 'test') in ll:' instead (consider-using-assignment-expr)
Then, applying the suggestion from the checker raises back the original warning (which seems like a bug to me):
ll = ["test"]
if TEST := "test" in ll:
raise ValueError("test in list")Warning:
test.py:4:11: R2004: Consider using a named constant or an enum instead of ''test''. (magic-value-comparison)
Configuration
Command used
pylint test.py --load-plugins="pylint.extensions.magic_value,pylint.extensions.code_style"Pylint output
************* Module test
test.py:4:11: R2004: Consider using a named constant or an enum instead of ''test''. (magic-value-comparison)Expected behavior
The last warning should not be raised IMO.
Pylint version
pylint 4.0.2
astroid 4.0.1
Python 3.13.8 (main, Oct 8 2025, 08:53:24) [GCC 11.4.0]OS / Environment
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
Additional dependencies
Metadata
Metadata
Assignees
Labels
Needs triage 📥Just created, needs acknowledgment, triage, and proper labellingJust created, needs acknowledgment, triage, and proper labelling