pytype icon indicating copy to clipboard operation
pytype copied to clipboard

Invalid [bad-unpacking] error when using "catch-all"

Open chuckwondo opened this issue 3 years ago • 1 comments

When using a "catch-all" with unpacking, pytype incorrectly reports a [bad-unpacking] error.

As a simple case:

first, *rest = ["foo"]

This is valid, where first is assigned "foo" and rest is assigned [], but pytype reports:

Cannot unpack 1 value into 2 variables [bad-unpacking]

When pytype analyzes such unpacking, it should not count the "catch-all" on the LHS (if there is one) in its variable count for comparison to the length of the value on the RHS.

Conversely, in the following case, Python will produce a ValueError, but pytype does not produce an error:

first, *rest = []

chuckwondo avatar May 18 '22 22:05 chuckwondo

thanks, looks like we have some errors in our sequence unpacking logic!

martindemello avatar May 24 '22 23:05 martindemello

Looks like this is fixed!

rchen152 avatar Aug 18 '22 23:08 rchen152