[Python-Dev] 2.5 and beyond

Tim Peters tim.peters at gmail.com
Fri Jun 30 12:01:17 CEST 2006


[Ka-Ping Yee, on
  http://www.python.org/dev/peps/pep-0356/
]
> Among them is this one:
>
>     Incorrect LOAD/STORE_GLOBAL generation
>     http://python.org/sf/1501934
>
> The question is, what behaviour is preferable for this code:
>
>     g = 1
>     def f():
>         g += 1
>
>     f()
>
> Should this raise an UnboundLocalError or should it increment g?
>
> (Or, in other words, should augmented assignment be considered
> a local binding like regular assignment, or not?)

Of course it should, since that's the way it _is_ treated in all
released Pythons, and there was no intent to change the semantics (let
alone a FutureWarning in 2.4 to alert users that the meaning was going
to change in 2.5).  The Reference Manual also makes no distinction
between assignment statements and augmented assignment statements in
any relevant respect.  The change in behavior here in 2.5 is plainly a
bug (although someone may want to argue "it should" be different in
P3K).


More information about the Python-Dev mailing list