Tuple parameter unpacking in 3.x

Martin Geisler mg at daimi.au.dk
Thu Oct 2 17:45:00 EDT 2008


Hi,

I just tried running my code using "python2.6 -3" and got a bunch of

  SyntaxWarning: tuple parameter unpacking has been removed in 3.x

warnings. I've read PEP-3113:

  http://www.python.org/dev/peps/pep-3113/

but I'm still baffled as to why you guys could remove such a wonderful
feature?!

I use tuple unpacking as very nice syntactic sugar to do sort of pattern
matching like in Haskell and ML. And in lambda expressions it looks so
elegant and works so natural ("pythonic"):

  ci.addCallback(lambda (ai, bi): ai * bi)

or

  map(lambda (i, s): (field(i + 1), s), enumerate(si))

Rewriting these to

  ci.addCallback(lambda abi: abi[0] * abi[1])

and

  map(lambda is: (field(is[0] + 1), is[1]), enumerate(si))

makes the code much uglier! And slightly longer.

PEP-3113 says that one can just unpack the argument on the first line in
the function and that not many people know about them. The first
argument is bogus for lambda expressions -- the PEP includes a rewriting
like the above, but neglects to comment on how bad the rewritten code
looks. The second argument is matter of who you ask -- I use Twisted and
have lots of callbacks like the ones above, and for me this language
feature is a big plus since it makes the code more readable.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 202 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20081002/62e6776a/attachment.sig>


More information about the Python-list mailing list