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

False positive: unnecessary-dict-index-lookup when deleting a key in a dictionary #5536

Closed
cpitclaudel opened this issue Dec 16, 2021 · 1 comment
Labels
Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@cpitclaudel
Copy link
Contributor

Bug description

Pylint suggests replacing a[k] below with v

# pylint: disable=missing-module-docstring
a = {"a": 1}
for k, v in a.items():
    if v % 2 == 0:
        del a[k]

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:5:12: R1733: Unnecessary dictionary index lookup, use 'v' instead (unnecessary-dict-index-lookup)

Expected behavior

Ideally, an error about modifying a dictionary during iteration; alternatively, no errors.

Pylint version

pylint 2.12.2

OS / Environment

No response

Additional dependencies

No response

@cpitclaudel cpitclaudel added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Dec 16, 2021
@DanielNoord
Copy link
Collaborator

This is a duplicate of #4716. A fix has been made in #5344 which will be released with pylint 2.13!

@DanielNoord DanielNoord added Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Dec 16, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

No branches or pull requests

3 participants