16

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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
user1659464
  • 313
  • 1
  • 3
  • 9
  • 10
    It says *possible* (and `W` is just a **w**arning). Evidently the introspection isn't deep enough to determine that `func1` always returns a two-tuple, and therefore that `func2` always returns a four-tuple. Given that you know it isn't a problem, you could add `# pylint: disable=unbalanced-tuple-unpacking` to the offending line. – jonrsharpe Jan 16 '15 at 08:48
  • 1
    this sounds like a false-positive that should be reported on pylint's issue tracker (https://bitucket.org/logilab/pylint/issues) – sthenault Jan 16 '15 at 13:59
  • 2
    @sthenault too few `'b'`s - **b**it**b**ucket! – jonrsharpe Jan 16 '15 at 14:20

1 Answers1

20

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

Asclepius
  • 57,944
  • 17
  • 167
  • 143