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

consider-dictionary-membership #4069

Closed
belm0 opened this issue Feb 4, 2021 · 0 comments · Fixed by #4997
Closed

consider-dictionary-membership #4069

belm0 opened this issue Feb 4, 2021 · 0 comments · Fixed by #4997
Labels
Enhancement ✨ Improvement to a component Proposal 📨
Milestone

Comments

@belm0
Copy link
Contributor

belm0 commented Feb 4, 2021

When testing if a key is contained in a dictionary, it's O(1) to use in directly on the dict object as opposed to O(N) through .keys().

So along the lines of consider-iterating-dictionary, there should be a check for this that suggests removing keys().

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Proposal 📨 labels Feb 6, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 13, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.0 milestone Sep 14, 2021
cdce8p pushed a commit to DanielNoord/pylint that referenced this issue Sep 14, 2021
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Feb 17, 2022
> Emitted when the keys of a dictionary are iterated through the
  ``.keys()`` method or when ``.keys()`` is used for a membership check.
  It is enough to iterate through the dictionary itself, ``for key in
  dictionary``. For membership checks, ``if key in dictionary`` is faster.

See pylint-dev/pylint#4069

Fixes: fleet-commander#279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Feb 17, 2022
> Emitted when the keys of a dictionary are iterated through the
  ``.keys()`` method or when ``.keys()`` is used for a membership check.
  It is enough to iterate through the dictionary itself, ``for key in
  dictionary``. For membership checks, ``if key in dictionary`` is faster.

See pylint-dev/pylint#4069

Fixes: fleet-commander#279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
olivergs pushed a commit to fleet-commander/fc-admin that referenced this issue Mar 3, 2022
> Emitted when the keys of a dictionary are iterated through the
  ``.keys()`` method or when ``.keys()`` is used for a membership check.
  It is enough to iterate through the dictionary itself, ``for key in
  dictionary``. For membership checks, ``if key in dictionary`` is faster.

See pylint-dev/pylint#4069

Fixes: #279
Signed-off-by: Stanislav Levin <slev@altlinux.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Proposal 📨
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants