[Python-Dev] Informal educator feedback on PEP 572 (was Re: 2018 Python Language Summit coverage, last part)
Chris Barker - NOAA Federal
chris.barker at noaa.gov
Tue Jul 3 01:44:36 EDT 2018
> On Jul 2, 2018, at 8:34 AM, Steven D'Aprano <steve at pearwood.info> wrote:
Guido has decided — and despite my concerns, I’m going to enjoy my new
loop-and-a half construct:-)
But a comment on this:
> comprehension are no more special than
> assignments inside any other expression. They bind in the current scope,
> same as always, and keep the sensible identity that these two
> expressions are exactly equivalent in their visible semantics:
> [x:=0, x:=1, x:=2]
> [x:=i for i in (0, 1, 2)]
> including assignments.
Sure — and I don’t think that’s confusing.
However, generator expressions ( why don’t we call them generator
comprehensions?) are a different story, as they may be run at some
arbitrary time in the future. This hasn’t been an issue (except for
the loop variable, which has been addressed) because:
1) Much of the time, the gen_ex is run right away, in-line.
2) There aren’t many ways to manipulate the local namespace in a gen_ex.
With assignment expressions, it will be much easier to manipulate the
local namespace, so there is room for some real confusion here.
So a real local namespace gen_exp (and comprehensions, for
consistency) would be nice.
However, that ship has pretty much sailed.
Will it end up being a common problem? Probably not, because (a) is
still the case, and := will be used infrequently, and hopefully with
unlikely to clash names.
And as for all the other languages that have assignment expressions?
Do they have constructs like generator expressions?
More information about the Python-Dev