Search code examples
pythonpylint

What is the "parameter unpacking" error in pylint 1.4?


I have this piece of python code:

d = {"a": {}}
d["a"] = sorted(d["a"].iteritems(), key=lambda (k,v,): len(v.get('b')), reverse=True)

When I run this through pylint 1.4, I receive the warning: "E: 3,48: Parameter unpacking specified (parameter-unpacking)"

What does this error mean, and does it actually indicate something wrong in the code?


Solution

  • Iterating through a dictionary-iteritems object (which is done by calling its .next() method) yields 2-tuples. Your lambda function is taking two parameters, but the 2-tuple yielded by the dict-iteritems object is a single object.

    You can fix this by just indexing into the tuple instead:

    d["a"] = sorted(d["a"].iteritems(), key=lambda x: len(x[1].get('b')), reverse=True)