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 negative for consider-iterating-dictionary when using not or list #5323

Closed
Pierre-Sassoulas opened this issue Nov 16, 2021 · 0 comments · Fixed by #5331
Closed

False negative for consider-iterating-dictionary when using not or list #5323

Pierre-Sassoulas opened this issue Nov 16, 2021 · 0 comments · Fixed by #5331
Assignees
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Milestone

Comments

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Nov 16, 2021

Bug description

In the following sample a.py, only the last if raise a consider-iterating-dictionary

metadata = {}
if "a" not in list(metadata.keys()):
    print(1)
if "a" not in metadata.keys():
    print(1)
if "a" in list(metadata.keys()):
    print(1)
if "a" in metadata.keys():
    print(1)

Command used

pylint a.py

Pylint output

************* Module a
a.py:8:10: C0201: Consider iterating the dictionary directly instead of calling .keys() (consider-iterating-dictionary)

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

Expected behavior

All four ifs are consider-iterating-dictionary

Pylint version

pylint 2.11.1
astroid 2.8.5
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0]
@Pierre-Sassoulas Pierre-Sassoulas added Help wanted 🙏 Outside help would be appreciated, good for new contributors Good first issue Friendly and approachable by new contributors False Negative 🦋 No message is emitted but something is wrong with the code labels Nov 16, 2021
@Pierre-Sassoulas Pierre-Sassoulas changed the title False negative for consider-iterating-dictionary when using not or list False negative for consider-iterating-dictionary when using not or list or assert Nov 16, 2021
@Pierre-Sassoulas Pierre-Sassoulas changed the title False negative for consider-iterating-dictionary when using not or list or assert False negative for consider-iterating-dictionary when using not or list Nov 16, 2021
@yushao2 yushao2 self-assigned this Nov 17, 2021
@DanielNoord DanielNoord added this to the 2.13.0 milestone Nov 17, 2021
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.13.0, 2.12.2 Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants