[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Bruce Leban bruce at leapyear.org
Mon Sep 26 18:27:47 CEST 2011

On Mon, Sep 26, 2011 at 6:47 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> Adding new keywords is a big, big step that demands a compelling
> justification.


> Now that I have come up with a way to make this
> syntactic sugar for existing usage of nonlocal rather than a new
> concept, I flatly oppose introduction of a new name for something
> which is, at a fundamental level, just a variation on existing
> functionality. I'd rather continue with the status quo indefinitely if
> people truly find this variant intolerable.

You can always abuse an existing keyword to avoid adding a new one. For
example, this could instead be

pass x in from expression
for x from expression
with x from expression

etc. These would surely be rejected because the keywords are used with an
entirely different meaning and that makes the language harder to read and

The keyword nonlocal means that this binding is not local to this scope but
can be found up the call stack. In contrast, your usage means the binding is
local to this function, created before the function is called the first time
and shared with all calls to this function. Those are orthogonal scopes.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110926/f2837f8d/attachment.html>

More information about the Python-ideas mailing list