-
Notifications
You must be signed in to change notification settings - Fork 127
Prefer iterating dict instead of calling dict.keys() #138
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #138 +/- ##
=======================================
Coverage 70.93% 70.93%
=======================================
Files 49 49
Lines 4816 4816
Branches 812 812
=======================================
Hits 3416 3416
Misses 1066 1066
Partials 334 334
Continue to review full report at Codecov.
|
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.
In general it's a good idea. However dict.keys()
to dict iteration can cause dict size change during iteration
bugs. I'd prefer to delay this postpone this change for 3.1 release.
First we should bring the cidict module to 100% test coverage (including edge cases). Then we should remove all functions that are provided by UserDict.IterableUserDict
or collections.Mapping
. Then we can modernize the code.
This would already be true on Python 3. On Python 3, you can't both iterate over |
@jdufresne, can I rebase this? (It's not a problem for me, but I don't want to cause conflicts if you're working on it.) |
Sure, go ahead, thanks. I normally just grep for |
Rebased on the latest master branch. Thanks. |
Sorry for the delay in reviewing. |
That is fine with me. Please feel free to make additional changes should a review catch anything else. |
Calling dict.keys() is unnecessary. iter(dict) is equivalent to dict.keys(). Inspired by Lennart Regebro's talk "Prehistoric Patterns in Python" from PyCon 2017. https://www.youtube.com/watch?v=V5-JH23Vk0I
Calling
dict.keys()
is unnecessary.iter(dict)
is equivalent todict.keys()
. Inspired by Lennart Regebro's talk "Prehistoric Patterns in Python" from PyCon 2017.https://www.youtube.com/watch?v=V5-JH23Vk0I