[Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

Nick Coghlan ncoghlan at gmail.com
Mon May 28 09:20:09 EDT 2018

On 28 May 2018 at 10:17, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Nick Coghlan wrote:
>> Aye, while I still don't want comprehensions to implicitly create new
>> locals in their parent scope, I've come around on the utility of letting
>> inline assignment targets be implicitly nonlocal references to the nearest
>> block scope.
> What if you're only intending to use it locally within the
> comprehension? Would you have to put a dummy assignment in
> the surrounding scope to avoid a NameError? That doesn't
> sound very nice.

The draft PEP discusses that - it isn't saying "Always have them raise
TargetNameError, now and forever", it's saying "Have them raise
TargetNameError in the first released iteration of the capability, so we
can separate the discussion of binding semantics in scoped expressions from
the discussion of declaration semantics".

I still want to leave the door open to giving comprehensions and lambdas a
way to declare and bind truly local variables, and that gets more difficult
if we go straight to having the binding expressions they contain
*implicitly* declare new variables in the parent scope (rather than only
binding previously declared ones).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180528/1dee11ac/attachment.html>

More information about the Python-ideas mailing list