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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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()