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

dict-iter-missing-items does not recognize tuple keys #3283

Closed
lovetox opened this issue Dec 1, 2019 · 1 comment · Fixed by #4939
Closed

dict-iter-missing-items does not recognize tuple keys #3283

lovetox opened this issue Dec 1, 2019 · 1 comment · Fixed by #4939
Labels
Enhancement ✨ Improvement to a component
Milestone

Comments

@lovetox
Copy link

lovetox commented Dec 1, 2019

Steps to reproduce

mydict = { (a, b): c }

for (a, b) in mydict:
   print(a, b)

Current behavior

Introduced with #2761

This yields now dict-iter-missing-items

if iterate with mydict.keys() it yields consider-iterating-dictonary

so there is no way anymore to iterate such a dict without warning or error, with one exception, using items() and casting the values to something like _ which is ugly, or not unpacking at all in the for line.

Expected behavior

Recognize if keys are tuples and dont throw this error

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.5.4 (v3.5.4:3f56838, Aug 8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)]

@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label May 3, 2020
@Pierre-Sassoulas
Copy link
Member

It makes sense, thank you for creating the issue.

DanielNoord added a commit to DanielNoord/pylint that referenced this issue Aug 31, 2021
This fixes a false positive emitted for dictionaries that contain only
tuples as keys. This makes unpacking the dictionary without calling
`.items()` valid.
This closes pylint-dev#3283
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.0 milestone Aug 31, 2021
Pierre-Sassoulas pushed a commit that referenced this issue Aug 31, 2021
This fixes a false positive emitted for dictionaries that contain only
tuples as keys. This makes unpacking the dictionary without calling
`.items()` valid.
This closes #3283
DanielNoord added a commit to DanielNoord/ruff that referenced this issue Feb 6, 2024
dhruvmanila added a commit to astral-sh/ruff that referenced this issue Feb 19, 2024
## Summary

References #970.

Implements
[`dict-iter-missing-items`](https://pylint.readthedocs.io/en/latest/user_guide/messages/error/dict-iter-missing-items.html).

Took the tests from "upstream"
[here](https://github.com/DanielNoord/pylint/blob/main/tests/functional/d/dict_iter_missing_items.py).

~I wasn't able to implement code for one false positive, but it is
pretty estoric: pylint-dev/pylint#3283. I
would personally argue that adding this check as preview rule without
supporting this specific use case is fine. I did add a "test" for it.~
This was implemented.

## Test Plan

Followed the Contributing guide to create tests, hopefully I didn't miss
any.
Also ran CI on my own fork and seemed to be all okay 😄 

~Edit: the ecosystem check seems a bit all over the place? 😅~ All good.

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
nkxxll pushed a commit to nkxxll/ruff that referenced this issue Mar 10, 2024
## Summary

References astral-sh#970.

Implements
[`dict-iter-missing-items`](https://pylint.readthedocs.io/en/latest/user_guide/messages/error/dict-iter-missing-items.html).

Took the tests from "upstream"
[here](https://github.com/DanielNoord/pylint/blob/main/tests/functional/d/dict_iter_missing_items.py).

~I wasn't able to implement code for one false positive, but it is
pretty estoric: pylint-dev/pylint#3283. I
would personally argue that adding this check as preview rule without
supporting this specific use case is fine. I did add a "test" for it.~
This was implemented.

## Test Plan

Followed the Contributing guide to create tests, hopefully I didn't miss
any.
Also ran CI on my own fork and seemed to be all okay 😄 

~Edit: the ecosystem check seems a bit all over the place? 😅~ All good.

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants