-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
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
The code is:
series = [1, 2, 3, 4, 5]
output_list = [
(item, series[index])
for index, item in enumerate(series, start=1)
if index < len(series)
]
print(output_list)Which produces the output:
[(1, 2), (2, 3), (3, 4), (4, 5)]
When there is a start parameter on the enumeration, "item" and "series[index]" are not the same object
but pylint suggests:
R1736: Unnecessary list index lookup, use 'item' instead (unnecessary-list-index-lookup)
If we follow the advice we would get a different result set
[(1, 1), (2, 2), (3, 3), (4, 4)]
I think the error should be suppressed when there's a start index on the enumeration
Configuration
No response
Command used
pylint .\pylint.pyPylint output
************* Module pylint
pylint.py:4:11: R1736: Unnecessary list index lookup, use 'item' instead (unnecessary-list-index-lookup)Expected behavior
No error at all
Pylint version
pylint 2.14.1
astroid 2.11.5
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)]OS / Environment
No response
Additional dependencies
No response
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