forked from pylint-dev/pylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added additional logic and tests for (pylint-dev#3389)
- Loading branch information
Showing
5 changed files
with
46 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
"""Emit a message for iteration through dict keys and subscripting dict with key.""" | ||
|
||
# pylint: disable=missing-docstring, import-error, useless-object-inheritance, unsubscriptable-object, too-few-public-methods | ||
# pylint: disable=missing-docstring,unsubscriptable-object | ||
|
||
def bad(): | ||
a_dict = {1:1, 2:2, 3:3} | ||
for k in a_dict:# [consider-using-dict-items] | ||
for k in a_dict: # [consider-using-dict-items] | ||
print(a_dict[k]) | ||
another_dict = dict() | ||
for k in another_dict:# [consider-using-dict-items] | ||
for k in another_dict: # [consider-using-dict-items] | ||
print(another_dict[k]) | ||
|
||
|
||
def good(): | ||
a_dict = {1:1, 2:2, 3:3} | ||
for k in a_dict: | ||
print(k) | ||
|
||
out_of_scope_dict = dict() | ||
|
||
def another_bad(): | ||
for k in out_of_scope_dict: # [consider-using-dict-items] | ||
print(out_of_scope_dict[k]) | ||
|
||
def another_good(): | ||
for k in out_of_scope_dict: | ||
k = 1 | ||
k = 2 | ||
k = 3 | ||
print(out_of_scope_dict[k]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
consider-using-dict-items:7:4:bad:Consider iterating with .items() | ||
consider-using-dict-items:10:4:bad:Consider iterating with .items() | ||
consider-using-dict-items:22:4:another_bad:Consider iterating with .items() |