New assignmens ...

Antoon Pardon antoon.pardon at
Mon Oct 25 05:20:52 EDT 2021

On 25/10/2021 01:46, Avi Gross via Python-list wrote:
> No, many things need not be as general as possible once you consider how
> much work it may take to develop code and how many bugs and oddities might
> be introduced and even how much it may slow the interpreter.
> I imagine you can create some fairly complex examples you can suggest should
> be handled for generality including some very indirect references created
> dynamically. The code to recognize any abstract use of symbols may not only
> slow down every operation of even the simplest type but generate all kinds
> of error messages nobody will understand, let alone translate into other
> languages properly! Right now, it is simpler. An error message can say that
> only certain simple usages are allowed.

I don't consider this a strong argument. Limiting the scope of the walrus operator
will just force people organizing there code where they will use a normal assignment.
So the resulting code will not be faster, less complex or generate less error messages
because the complexity of the assignment that is needed is still the same.

Or you force people to be "creative" as follows:

Suppose I would like to write a loop as follows:

     while ((a, b) := next_couple(a, b))[1]:
         do needed calculations

What I can do is write it as follows:

     while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]:
         do needed calculations

I really don't see what is gained by "forcing" me to right the second code over the first.

Antoon Pardon

More information about the Python-list mailing list