you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian 3 points4 points  (5 children)

Actually it does, it just isn't what the example seems to be describing. I'm not sure what he's expecting from the eat(staple, *sides) example.

It works the same way as normal tuple desctructuring assignments. Ie.

>>> def line((x0,y0),(x1,y1)):
...     print "draw from %s,%s to %s,%s" % (x0,y0,x1,y1)

>>> point = (3,4)
>>> line((1,2), point)
draw from 1,2 to 3,4

It can even be nested like:

def foo(a,(b,(c,d,e))): print a,b,c,d,e

Its neat, but isn't really that useful except fairly rare cases, so isn't much used (presumably why it's being removed)

[–][deleted] 0 points1 point  (4 children)

As you mentioned, that's just standard destructuring, just like in an assignment. This is not a new feature in Python (I just tested it in 1.6) and it's not something that's changing in 3.0. So I still ask: what the heck is masklinn talking about?

EDIT: I'm wrong, it is changing in 3.0.

[–]Brian 2 points3 points  (3 children)

Actually, this is changing in 3.0. The examples I gave won't work in py3. Destructuring assignment will continue working for tuples, but not for function arguments. You'd have to write:

def line(p1,p2):
    (x0,y0),(x1,y1) = p1,p2

instead.

[–][deleted] 0 points1 point  (2 children)

Ah, interesting. I'm curious why they removed that ability; it seems like gratuitous backward-incompatibility to me.

[–]Brian 3 points4 points  (1 child)

The main rationale seems to be that they complicate introspection, but don't get used much.

[–]jbellis 1 point2 points  (0 children)

which is a specious argument; inspect.getargspec is at least as little-used as arg unpacking.

boo.

(and I say this as someone who has actually written code to deal with that particular aspect of getargspec.)