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

Paul Moore p.f.moore at gmail.com
Wed Sep 28 09:10:04 CEST 2011

On 28 September 2011 01:56, Bruce Leban <bruce at leapyear.org> wrote:
> And it made
> me realize it would be weird if (to use one possible bikeshed color):
>     own x = y
> was not the same as
>     own x
>     x = y
> but I don't see how these can possibly be the same. You need the first case
> to do one time initialization and you must be able to change the value as in
> the second case or the feature is useless.

Equally to the point, if a function has

    own x = 1
    x = 1

it is *not* valid to remove the second line, as it runs at a different
time (runtime rather than define time). That is very weird.

Between these points and Arnaud Delobelle's point that code inside a
function should do nothing when the def itself is executed, I'm
getting more convinced that objects with persistent local scope should
be introduced *outside* the function body.

That either validates the default-argument hack as a valid response to
a specific requirement, or suggests some syntax added to the function
definition line. Or of course, just go with a normal (nested function)


More information about the Python-ideas mailing list