[Python-Dev] Tuple pack/unpack and the definition of AST Assign nodes
Thomas Lee
tom at vector-seven.com
Mon Jun 9 16:21:14 CEST 2008
Nick Coghlan wrote:
>
> I haven't looked at that code recently, but I believe the ADSL
> sequence in the assignment node is for statements where there are
> actually multiple assignment targets, such as:
>
> >>> p = x, y = 1, 2
> >>> p, x, y
> ((1, 2), 1, 2)
>
> Cheers,
> Nick.
>
Ah I see. A quick test verifies exactly this:
>>> import _ast
>>> ast = compile("p = x, y = 1, 2", "<string>", "exec",
_ast.PyCF_ONLY_AST)
>>> ast.body[0]
<_ast.Assign object at 0xb7d0122c>
>>> ast.body[0].targets
[<_ast.Name object at 0xb7d0124c>, <_ast.Tuple object at 0xb7d0128c>]
>>> ast.body[0].value
<_ast.Tuple object at 0xb7d0132c>
>>>
I thought this would have been implemented as nested Assign nodes, but
I'm obviously wrong. :) Thanks for the clarification.
Cheers,
T
More information about the Python-Dev
mailing list