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

Fix false pos. dict-iter-missing-items for tuple keys #4939

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -45,6 +45,10 @@ Release date: TBA

* Fix false positive for ``protected-access`` if a protected member is used in type hints of function definitions

* Fix false positive ``dict-iter-missing-items`` for dictionaries only using tuples as keys

Closes #3282


What's New in Pylint 2.10.3?
============================
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.11.rst
Expand Up @@ -51,3 +51,7 @@ Other Changes
Closes #4936

* Fix false positive for ``protected-access`` if a protected member is used in type hints of function definitions

* Fix false positive ``dict-iter-missing-items`` for dictionaries only using tuples as keys

Closes #3282
4 changes: 4 additions & 0 deletions pylint/checkers/typecheck.py
Expand Up @@ -1862,6 +1862,10 @@ def visit_for(self, node):
# the iterable is not a dict
return

if all(isinstance(i[0], nodes.Tuple) for i in inferred.items):
# if all keys are tuples
return

self.add_message("dict-iter-missing-items", node=node)


Expand Down
3 changes: 3 additions & 0 deletions tests/functional/d/dict_iter_missing_items.py
Expand Up @@ -2,6 +2,7 @@
from unknown import Uninferable

d = {1: 1, 2: 2}
d_tuple = {(1, 2): 3, (4, 5): 6}
l = [1, 2]
s1 = {1, 2}
s2 = {1, 2, 3}
Expand All @@ -21,3 +22,5 @@
pass
for k, v in Uninferable:
pass
for a, b in d_tuple:
pass
2 changes: 1 addition & 1 deletion tests/functional/d/dict_iter_missing_items.txt
@@ -1 +1 @@
dict-iter-missing-items:10:0::Unpacking a dictionary in iteration without calling .items()
dict-iter-missing-items:11:0::Unpacking a dictionary in iteration without calling .items()