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

unnecessary-list-index-lookup inconsistent when assigning to iterating object in iterable unpacking #6788

Closed
Tratori opened this issue Jun 1, 2022 · 2 comments · Fixed by #6808
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@Tratori
Copy link

Tratori commented Jun 1, 2022

Bug description

# pylint: disable=missing-docstring
myList = [1, 2, 3]

for a, b in enumerate(myList):
    myList[a] = 2

for a, b in enumerate(myList):
    myList[a], _ = (2, 1)

Configuration

No response

Command used

pylint test2.py

Pylint output

************* Module test2
test2.py:8:4: R1736: Unnecessary list index lookup, use 'b' instead (unnecessary-list-index-lookup)

------------------------------------------------------------------
Your code has been rated at 8.00/10 (previous run: 8.00/10, +0.00)

Expected behavior

I would expect the output for both loops to be the same. The latter loop leads to an unnecessary-list-index-lookup though.

Pylint version

pylint 2.14.0
astroid 2.11.5
Python 3.9.12 (main, Jun  1 2022, 11:38:51) 
[GCC 7.5.0]

OS / Environment

Ubuntu 20.04

Additional dependencies

No response

@Tratori Tratori added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 1, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the report, the second example looks like a false positive because the assumption of direct parentage here is violated (subscript.parent is a <Tuple.tuple l.8 ...):
https://github.com/PyCQA/pylint/blob/6e6927341aa38b2153a3ca7096f1a6447e135dbf/pylint/checkers/refactoring/refactoring_checker.py#L1921

cc/ @timmartin

I also see we have similar code in three places 👀 (grep for "Early termination" to find them quickly).

@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 1, 2022
@timmartin
Copy link
Contributor

Thanks for the heads-up, I don't mind taking a look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants