[Python-Dev] PEP 572: Assignment Expressions
Anthony Flury
anthony.flury at btinternet.com
Fri Apr 20 21:38:04 EDT 2018
I am entirely new to this list, but if I can I would like share my
comments :
* I do think this proposal <target> := <value> has merit in my
opinion; it does make some code more readable.
* I think readability is only improved if :
* target is restricted to a simple name - I don't see a benefit in
more complex targets
* chaining is not allowed - I think the construct :
while (line := input.read_row()) is not None:
process_line(line)
Is readable, but :
while (current_line := line := input.read_row()) is not
None:
line = process_line(line)
is not obvious - and certainly isn't any more obvious than :
while (line := input.read_row()) is not None:
current_line = line
line = process_line(line)
* The current expectations of how comprehensions work should also be
honored; I don't claim to have fully followed all of the discussions
around this, but it seems to me that comprehensions work in a
particular way because of a concerted effect (especially in Python
3) to make them that way. They are self contained and don't leak
values in their containing scope. Similarly I think that setting
variables within a comprehension is just for the benefit of readable
code within the comprehension - i.e. :
stuff = [[y, x/y] for x in range(5) for y in [f(x)]]
can become :
stuff = [[y := f(x), x/y] for x in range(5)]
So - overall from me a conditional +1 - conditions as above; if they are
not possible then -1 from me.
--
Anthony Flury
email : *Anthony.flury at btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*
More information about the Python-Dev
mailing list