Author ncoghlan
Recipients benjamin.peterson, brett.cannon, ncoghlan, rhettinger, scoder, serhiy.storchaka, steven.daprano, yselivanov
Date 2019-10-20.12:45:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571575548.97.0.110405470353.issue32856@roundup.psfhosted.org>
In-reply-to
Content
The benefit offered by the parent local scoping was that it made assignment expressions usable as a straightforward way to implement comprehension-based accumulators where you actually do want access to the final value after the comprehension completes (for example, pulling the example or counter-example out of a call to any() or all()).

The downside is that you need an explicit "del j" after the comprehension to ensure prompt cleanup in those cases where you *don't* need the temporary variable after the comprehension has finished running:

    >>> [(j:=i*i)+1/j for i in range(1, 3)]; del j # Clean up temp

However, that's still going to be clearer to most readers than writing:

    [j+1/j for i in range(1, 3) for j in [i*i]]

So even with the parent local scoping semantics, PEP 572 is still enough to make Yury's comment above still hold (i.e. the use case is too obscure to justify the extra code needed to optimise it)
History
Date User Action Args
2019-10-20 12:45:49ncoghlansetrecipients: + ncoghlan, brett.cannon, rhettinger, scoder, benjamin.peterson, steven.daprano, serhiy.storchaka, yselivanov
2019-10-20 12:45:48ncoghlansetmessageid: <1571575548.97.0.110405470353.issue32856@roundup.psfhosted.org>
2019-10-20 12:45:48ncoghlanlinkissue32856 messages
2019-10-20 12:45:48ncoghlancreate