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

Prevent warnings on dict / list index lookup with destructuring assignment #6808

Merged
merged 6 commits into from
Jun 4, 2022

Conversation

timmartin
Copy link
Contributor

Type of Changes

Type
🐛 Bug fix

Description

The checkers unnecessary-list-index-lookup and unnecessary-dict-index-lookup have a check that the usage of the index isn't appearing on the left hand side of an assignment. So for example:

for key, val in my_dict:
    my_dict[key] = 'x'

should not be a warning. However, this checker was not catching the case where the assignment was part of a destructuring expression, so there was a false positive for:

for key, val in my_dict:
    (my_dict[key], _) = ('x', 1)

This has been fixed.

Closes #6788

@coveralls
Copy link

coveralls commented Jun 2, 2022

Pull Request Test Coverage Report for Build 2436051343

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 95.523%

Totals Coverage Status
Change from base Build 2433586834: 0.002%
Covered Lines: 16259
Relevant Lines: 17021

💛 - Coveralls

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the speedy fix! Some trivial feedback.

@jacobtylerwalls jacobtylerwalls added the Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer label Jun 2, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.14.1 milestone Jun 2, 2022
@jacobtylerwalls jacobtylerwalls added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jun 2, 2022
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2022

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉This comment was generated for commit 7931c3f

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @timmartin , it looks great, I also like the new named function that makes it easier to understand the conditions.

@Pierre-Sassoulas Pierre-Sassoulas merged commit bdd470d into pylint-dev:main Jun 4, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Backported and removed Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer labels Jun 5, 2022
Pierre-Sassoulas pushed a commit that referenced this pull request Jun 5, 2022
Pierre-Sassoulas pushed a commit that referenced this pull request Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unnecessary-list-index-lookup inconsistent when assigning to iterating object in iterable unpacking
4 participants