On 2022-05-08 11:50, Steven D'Aprano wrote:
I don't have an opinion one way or the other, but there is a discussion
on Discourse about the walrus operator:

https://discuss.python.org/t/walrus-fails-with/15606/1


Just a quick straw poll, how would people feel about relaxing the
restriction on the walrus operator so that iterable unpacking is
allowed?

     # Currently a syntax error.
     results = (1, 2, (a, b) := (3, 4), 5)

Doesn't ':=' have a lower precedence than ',', so you're effectively asking it to bind:

    (1, 2, (a, b))

to:

    ((3, 4), 5)

?

which would create the following bindings:

     results = (1, 2, (3, 4), 5)
     a = 3
     b = 4

A more complex example:

     expression = "uvwxyz"
     results = (1, 2, ([a, *b, c] := expression), 5)

giving:

     results = (1, 2, "uvwxyz", 5)
     a = "u"
     b = ("v", "w", "x", "y")
     c = "z"


Thoughts?

_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/7IYW3X6RPEMWCTFR42Q4U7FTV3MXL6GX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to