[Python-Dev] replacing 'global'

Alex Martelli aleaxit at yahoo.com
Tue Oct 28 04:22:31 EST 2003

On Tuesday 28 October 2003 02:48 am, Greg Ewing wrote:
> Alex Martelli <aleaxit at yahoo.com>:
> > My slight preference for leaving += and friends alone is that
> > a function using them to rebind nonlocals would be hard to
> > read
> Using my "outer" suggestion, augmented assignments to
> nonlocals would be written
>   outer x += 1
> which would make the intention pretty clear, I think.

Absolutely clear, and wonderful.  Pity that any alternative to
'global' has been declared "a lost cause" by Guido.

I'd still like to forbid "side effect rebinding" via statements
such as class, def, import, for, i.e., no
    outer def f(): ...
and the like; i.e., the 'outer' statement should be
    'outer' expr_stmt
(in Grammar/Grammar terms) with the further constraint
that the expr_stmt must be an assignment (augmented or
not); and the outer statement should not be a 'small_stmt',
so as to avoid the ambiguity of
    outer x=1; y=2
(is this binding a local or nonlocal name 'y'?).


More information about the Python-Dev mailing list