Python 3000 idea: reversing the order of chained assignments

Virgil Dupras hardcoded.software at gmail.com
Wed Mar 21 22:13:42 EDT 2007


On Mar 21, 10:05 pm, Steve Holden <s... at holdenweb.com> wrote:
> Virgil Dupras wrote:
> > On Mar 21, 9:24 pm, Steve Holden <s... at holdenweb.com> wrote:
> >> Marcin Ciura wrote:
> >>> Steven D'Aprano wrote:
> >>>>>>> x, y, z = 1, 2, 3
> >>>>>>> x = y = z
> >>>>>>> x, y, z
> >>>> (3, 3, 3)
> >>>> I certainly wouldn't expect to get (2, 3, 3).
> >>> Neither would I. I must have expressed myself not clearly enough.
> >>> Currently
> >>> x = y = z
> >>> is roughly equivalent to
> >>> x = z
> >>> y = z
> >>> I propose to change it to
> >>> y = z
> >>> x = z
> >>> Cheers,
> >>>    Marcin
> >> The difference being ... ?
> >> --
> >> Steve Holden       +44 150 684 7255  +1 800 494 3119
> >> Holden Web LLC/Ltd          http://www.holdenweb.com
> >> Skype: holdenweb    http://del.icio.us/steve.holden
> >> Recent Ramblings      http://holdenweb.blogspot.com
>
> > I think I see what Marcin means. The 'node' is changed too fast in the
> > chain, and next is assigned to 'nextnode' instead of being assigned to
> > node.
>
> >>>> class Node:
> > ...     pass
> > ...
> >>>> node = Node()
> >>>> nextnode = Node()
> >>>> backup_node = node
> >>>> node = node.next = nextnode
> >>>> node.next is node
> > True
> >>>> hasattr(backup_node,'next')
> > False
>
> So we should take the already well-defined semantics of assignment and
> change them because it seems more obvious to J. Random User? I think I
> might be a little concerned about potential code breakage there.
>
> regards
>   Steve
> --
> Steve Holden       +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd          http://www.holdenweb.com
> Skype: holdenweb    http://del.icio.us/steve.holden
> Recent Ramblings      http://holdenweb.blogspot.com

I totally agree. This assignment is way too ambiguous anyway.
Readability first. I just wanted to enlighten the readers on what the
problem actually was since it wasn't obvious in the original post.




More information about the Python-list mailing list