New assignmens ...
antoon.pardon at vub.be
Tue Oct 26 11:42:22 EDT 2021
Op 25/10/2021 om 23:03 schreef Chris Angelico:
> On Tue, Oct 26, 2021 at 7:18 AM Antoon Pardon <antoon.pardon at vub.be> wrote:
>> Op 25/10/2021 om 20:39 schreef Chris Angelico:
>>> On Tue, Oct 26, 2021 at 5:35 AM Antoon Pardon <antoon.pardon at vub.be> wrote:
>>>> By putting limits on the walrus code, you are not reducing complexity, you are increasing it.
>>>> You are increasing complexity because you can't just reuse the code that handles an ordinary
>>>> assignment. You now need specific code to limit it's use.
>>> What does this code do?
>>> while x, y := foo():
>>> Is it more complicated or less complicated when arbitrary assignment
>>> targets are permitted?
>> Well I would guess it would do something similar to
>> while [x, y := foo()]:
> And does it unpack what foo returns?
> Should it?
1) No it doesn't.
2) I don't care. This is IMO not a question of what should or should not, but just a
question of deciding how you want to treat this. I guess that since it doesn't unpack
already, this behaviour is more or less fixed for futere releases. Should the python
developers in the future decide that de walrus operator can unpack things. The above
code will not unpack in order to not break already existing code and if you want
to unpack one will have to write something like:
while [(x, y) := foo()]:
But the answer to that second question has very little relevance to how complicated the
parser will be. It is just deciding which of , or := has a higher precedence. Since that
decision has already been more or less made, there is not much to decide here either.
More information about the Python-list