Andrew Koenig wrote: > Of course, this usage shows that the syntax is unnecessary in this context, > but what I care about is > > def f(x as (a, b)): > # ... > > which has the advantage over the alternative > > def f(x): > (a, b) = x > # ... > > that if you call f with the wrong arguments, you get a clearer diagnostic > message.
Doesn't tuple unpacking give you what you want here already? Py> def f((a, b)): ... print a, b ... Py> f(1, 2) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: f() takes exactly 1 argument (2 given) Py> f((1, 2)) 1 2 A couple of more complex examples: Py> def f((a, b), (c, d)): ... print a, b, c, d ... Py> f((1, 2), (3, 4)) 1 2 3 4 Py> def f((a, b, (c, d))): ... print a, b, c, d ... Py> f((1, 2, (3, 4))) 1 2 3 4 About the only downside is the need to rebuild the tuple if you actually need it. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com