Pylint warning: Possible unbalanced tuple unpacking with sequence

user1659464 picture user1659464 · Jan 16, 2015 · Viewed 8.2k times · Source

I have a piece of Python code:

def func1():                                                                                                                  
    a=set()
    b = ','.join(map(str, list(a)))
    return  b, []

def func2():
    d = 1
    e = 2
    return func1() + (d, e,)

def main():
    a,b,c,d = func2()

if __name__ == '__main__':
    main()

When I run it through pylint (1.4.0), I receive the warning:

W: 12, 4: Possible unbalanced tuple unpacking with sequence: left side has 4 label(s), right side has 3 value(s) (unbalanced-tuple-unpacking)

It seems that func2 will always return four results. What does the error mean and why?

Answer

The Chess Guy 20  picture The Chess Guy 20 · Feb 28, 2019

If the warning is erroneous, it can be disabled by appending # pylint: disable=unbalanced-tuple-unpacking to the line.