-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 a false positive for consider-using-dict-items
#9594
Merged
Pierre-Sassoulas
merged 8 commits into
pylint-dev:main
from
mbyrnepr2:9554_false_positive_consider_using_dict_items
May 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
13accb5
Fix a false positive for ``consider-using-dict-items`` when iteratingβ¦
mbyrnepr2 bf17fd7
Update doc/whatsnew/fragments/9554.false_positive
mbyrnepr2 9cc8a2a
Update tests/functional/c/consider/consider_using_dict_items.py
mbyrnepr2 b3d15fd
Update tests/functional/c/consider/consider_using_dict_items.py
mbyrnepr2 530d1e8
Regenerate the functional test output after change to the test module.
mbyrnepr2 0bd8a1a
Remove the unnecessary disable.
mbyrnepr2 7b5ddea
Run black.
mbyrnepr2 1f2a0da
Regenerate functional test output again (after running black).
mbyrnepr2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fix a false positive for ``consider-using-dict-items`` when iterating ``os.environ`` using the ``os.environ.keys()`` operation and then deleting an item using the key as a lookup. | ||
|
||
Closes #9554 |
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
29 changes: 15 additions & 14 deletions
29
tests/functional/c/consider/consider_using_dict_items.txt
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,16 +1,17 @@ | ||
consider-using-dict-items:6:4:7:24:bad:Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:9:4:10:30:bad:Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:21:4:22:35:another_bad:Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:40:0:42:18::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:44:0:45:20::Consider iterating with .items():UNDEFINED | ||
consider-iterating-dictionary:47:10:47:23::Consider iterating the dictionary directly instead of calling .keys():INFERENCE | ||
consider-using-dict-items:47:0:48:20::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:54:0:55:24::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:67:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:7:4:8:24:bad:Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:10:4:11:30:bad:Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:22:4:23:35:another_bad:Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:41:0:43:18::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:45:0:46:20::Consider iterating with .items():UNDEFINED | ||
consider-iterating-dictionary:48:10:48:23::Consider iterating the dictionary directly instead of calling .keys():INFERENCE | ||
consider-using-dict-items:48:0:49:20::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:55:0:56:24::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:68:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:71:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:69:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:72:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:75:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-iterating-dictionary:86:25:86:42::Consider iterating the dictionary directly instead of calling .keys():INFERENCE | ||
consider-using-dict-items:86:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:103:0:105:24::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:73:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:76:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-iterating-dictionary:87:25:87:42::Consider iterating the dictionary directly instead of calling .keys():INFERENCE | ||
consider-using-dict-items:87:0:None:None::Consider iterating with .items():UNDEFINED | ||
consider-using-dict-items:104:0:106:24::Consider iterating with .items():UNDEFINED | ||
consider-iterating-dictionary:112:11:112:28::Consider iterating the dictionary directly instead of calling .keys():INFERENCE |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The false positive is more generic than just
os.environ
, right ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is indeed true and I made the distinction here in the public-facing doc (compared to the commit message) because I thought it might sound odd since this situation suggests a modified iterating dict error would occur (which doesnβt happen in the case of os.environ because it is dict-like but also a bit special.
Having said that Iβm not against using the word dict here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I just checked and the commit message is the same π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's only a FP for
os.environ
because it's special then my suggestion is wrong πThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it would manifest for any dict but for a standard dict you would also have the modify iterating dict error; but I could be overthinking that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant that you donβt run into modify iterating dict error for os.environ which is why I say itβs a bit special.