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

Fix false positive when testing for-loops for unbalanced unpacking (W0644) #8892

Merged

Conversation

Neowizard
Copy link
Contributor

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

When checking for-loops for unbalanced dict unpacking, Pylint would compare the length of the targets with the length of the values iterable. However, since the for-loop would iterate the values and unpack each value in turn, Pylint should compare the length of the targets with the length of each value (and not the total length of values).

Closes #8156

…mber of targets to the size of each value, instead of the number of values, since the for loop will iterate the values and unpack each in turn onto the targets.
@github-actions

This comment has been minimized.

Neowizard and others added 5 commits July 27, 2023 20:16
…king. The original implementation would use `NodeNG.get_children()` which would return the AST subnodes for the Dict (i.e. all the keys and values), and not just the keys.
…packing.

Star unpacking requires there to be at least as many values to unpack as targets, so the unpacking is considered valid if the number of targets equal the number of values or if it's a star-unpacking with at least as many values as targets
@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Merging #8892 (0fe5f2e) into main (6f3030e) will increase coverage by 0.00%.
Report is 10 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8892   +/-   ##
=======================================
  Coverage   95.75%   95.76%           
=======================================
  Files         173      173           
  Lines       18604    18639   +35     
=======================================
+ Hits        17815    17850   +35     
  Misses        789      789           
Files Changed Coverage Ξ”
pylint/checkers/variables.py 97.22% <100.00%> (+0.04%) ⬆️

... and 4 files with indirect coverage changes

…ced-dict-unpacking to complete test code coverage
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

…value`. Also refactored the code a bit for readability
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code backport maintenance/3.3.x labels Jul 30, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.6 milestone Jul 30, 2023
@Pierre-Sassoulas Pierre-Sassoulas added the Needs review πŸ” Needs to be reviewed by one or multiple more persons label Aug 15, 2023
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.

Note to self: find out if it closes more issues before merging.

@Neowizard
Copy link
Contributor Author

@mbyrnepr2, let me know if my latest commit is what you had in mind

@mbyrnepr2
Copy link
Member

Yes looks great @Neowizard πŸ‘

mbyrnepr2
mbyrnepr2 previously approved these changes Aug 30, 2023
Copy link
Member

@mbyrnepr2 mbyrnepr2 left a comment

Choose a reason for hiding this comment

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

πŸ‘

@DanielNoord DanielNoord enabled auto-merge (squash) September 4, 2023 06:48
@DanielNoord DanielNoord merged commit 7b72c39 into pylint-dev:main Sep 4, 2023
44 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2023

The backport to maintenance/2.17.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-maintenance/2.17.x maintenance/2.17.x
# Navigate to the new working tree
cd .worktrees/backport-maintenance/2.17.x
# Create a new branch
git switch --create backport-8892-to-maintenance/2.17.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 7b72c392f85aa15d26acd7448fed830e0fa97656
# Push it to GitHub
git push --set-upstream origin backport-8892-to-maintenance/2.17.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-maintenance/2.17.x

Then, create a pull request where the base branch is maintenance/2.17.x and the compare/head branch is backport-8892-to-maintenance/2.17.x.

@DanielNoord
Copy link
Collaborator

@Pierre-Sassoulas How far are we to releasing 3.x? Do we really still need to backport?

@Pierre-Sassoulas
Copy link
Member

I would say still pretty far (we did not start #3512 or anything in https://github.com/pylint-dev/pylint/issues?q=is%3Aopen+is%3Aissue+label%3A%22Blocker+%F0%9F%99%85%22 yet). But if something is really hard to backport we're not obligated to do it (hard defined as "massive cherry-pick conflict" right now but it could evolve to "any cherry-pick conflicts" if we want)

@Pierre-Sassoulas Pierre-Sassoulas added Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer and removed Needs review πŸ” Needs to be reviewed by one or multiple more persons labels Sep 4, 2023
@Pierre-Sassoulas
Copy link
Member

(Added the "needs backport" label in order to remember that at 2.17.6 release time, it does not mean that I think we NEED to backport :) )

@DanielNoord
Copy link
Collaborator

Thanks! I'm fine with backporting as well, but can't check out pylint on the laptop I'm currently on.

@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 backport maintenance/3.3.x labels Oct 2, 2023
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.

False reports on W0644 unbalanced-dict-unpacking in pylint 2.16.0
5 participants