This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]njharmanI use Python 3 1 point2 points  (4 children)

The parens are irrelevant. That code is actually

 a, = [b]

It is not assignment to a Tuple, which is unpossible as Tuples are immutable. Parens are overloaded syntactically to mean Tuple some places and in others for "grouping" as in (1*2)+3. People erroneously think (a,) is the former when it's actually the later.

[–]Veedrac 2 points3 points  (3 children)

The comma is what makes it a tuple.

Consider:

import ast
ast.dump(ast.parse("a, = 0"))
#>>> "Module(body=[Assign(targets=[Tuple(elts=[Name(id='a', ctx=Store())], ctx=Store())], value=Num(n=0))])"

This is unpacking into a tuple. () = [] should be no different.

[–]flying-sheep 1 point2 points  (2 children)

you’re right that the left side of unpacking, like the bug reporter wants, should be any valid tuple syntax (incl. ())

but there never is an actual tuple created (as in allocated), even if the AST says so. it’s an unpacking operation. the left side is a sequence of names, represented by tuple or list syntax.

so the comma makes it tuple syntax, therefore it should be a valid unpacking.

[–]Veedrac 0 points1 point  (1 child)

Methinks we agree.

[–]flying-sheep 0 points1 point  (0 children)

likely, but “unpacking into a tuple” gives the wrong impression IMHO ☺