[Python-Dev] Tuple pack/unpack and the definition of AST Assign nodes (original) (raw)
Thomas Lee tom at vector-seven.com
Mon Jun 9 15:43:27 CEST 2008
- Previous message: [Python-Dev] Assignment to None
- Next message: [Python-Dev] Tuple pack/unpack and the definition of AST Assign nodes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In porting one of the old peephole optimizations to the new AST compiler I noticed something weird going on with the following code:
a, b, c = 1, 2, 3
Now, as you would expect this gets parsed into an Assign node. That Assign node looks like the following:
Assign.targets = [Tuple(Name(a), Name(b), Name(c))] Assign.value = Tuple(1, 2, 3)
What's weird here is that Assign.targets is an asdl_seq ... why are we wrapping the names in a Tuple() node? Shouldn't it look something more like this:
Assign.targets = [Name(a), Name(b), Name(c)]
I understand that parsing the testlist might yield a tuple and it was thus easier to just use the tuple rather than unpack it into an asdl_seq ... but if this was the intention, then why is Assign.targets an expr* rather than a plain old expr?
Cheers, Tom
- Previous message: [Python-Dev] Assignment to None
- Next message: [Python-Dev] Tuple pack/unpack and the definition of AST Assign nodes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]