-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
False 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
If I run pylint on the following:
item = (1,4,2,5)
for item in item:
print(item)
(I agree this is very bad practice, I encountered this while cleaning up an ugly codebase)
I get the following error:
file.py:2:12: E0602: Undefined variable 'item' (undefined-variable)
But this makes not much sense, since the variable is defined. Likely pylint reasons that since for
assign a value to item
, at the time the item
is read as source of items, item
is not defined, but it is.
Now it is definitely a good idea to generate a warning for this, but the variable is defined, so I think this is a false positive for E0602?
Command used
pylint file.py
Pylint output
************* Module file
file.py:1:0: C0114: Missing module docstring (missing-module-docstring)
file.py:2:12: E0602: Undefined variable 'item' (undefined-variable)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Expected behavior
Not mentioning E0602.
Pylint version
pylint 3.0.3
astroid 3.0.2
Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0]
Metadata
Metadata
Assignees
Labels
False 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