-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Suggest to iterate thorough dict items() instead of keys #3389
Comments
Thanks for the report! |
for d in a_dict.values(): |
Opened PR #4445 , please take a look :) There might be some issues as it is my first time contributing and I'm still not 100% sure if I'm doing it right |
@ursmaheshj Could you explain what you mean, I'm not quite following? At least I can't think of any case where I would use |
|
Thanks so much for your work here! An hour ago I was going to log a bug against this change, but it turned out that my code contained an insidious little bug where it wasn't iterating over a data structure as it should've been. Thanks again! |
Pylint 2.9 introduced new checker: > Emitted when iterating over the keys of a dictionary and accessing the value by index lookup. Both the key and value can be accessed by iterating using the .items() method of the dictionary instead. See pylint-dev/pylint#3389 Fixes: fleet-commander#279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Pylint 2.9 introduced new checker: > Emitted when iterating over the keys of a dictionary and accessing the value by index lookup. Both the key and value can be accessed by iterating using the .items() method of the dictionary instead. See pylint-dev/pylint#3389 Fixes: fleet-commander#279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Pylint 2.9 introduced new checker: > Emitted when iterating over the keys of a dictionary and accessing the value by index lookup. Both the key and value can be accessed by iterating using the .items() method of the dictionary instead. See pylint-dev/pylint#3389 Fixes: #279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
It'll be great to recognize loops that could iterate through items() instead of keys.
Example of problematic code pattern:
The text was updated successfully, but these errors were encountered: