[Python-Dev] nonlocal keyword in 2.x?
"Martin v. Löwis"
martin at v.loewis.de
Thu Oct 22 22:57:32 CEST 2009
exarkun at twistedmatrix.com wrote:
> On 08:24 pm, martin at v.loewis.de wrote:
>> Mike Krell wrote:
>>> Is there any possibility of backporting support for the nonlocal keyword
>>> into a 2.x release?
>> If so, only into 2.7. Can you please explain why it would be desirable
>> to do that? 2.7 will likely be the last 2.x release, so only a fairly
>> small portion of the applications would be actually able to use this (or
>> any other new feature added to 2.7): most code supporting 2.x will also
>> have to support 2.6, so the keyword won't be available to such code,
> For the same reason that it is desirable to backport all of the other
> changes from 3.x - because it makes the 2.x to 3.x transition easier.
> If Python 2.7 supports the nonlocal keyword, then 2.7 becomes that much
> better of a stepping stone towards 3.x.
What use has such a stepping stone? Why, and (more importantly) when
would anybody currently supporting 2.x give up 2.6 and earlier, and
only support 2.7? And, if they chose to do so, why would they not move
the code base to 3.x right away?
> You've suggested that most 2.x code will have to support 2.6 and so
> won't be able to use the nonlocal keyword even if it is added to 2.7.
> This precise argument could be applied to all of the features in 2.6
> which aim to bring it closer to 3.x.
Not so. One of the features added to 2.6 was the 3k warning. This
warning can be used without any modification to the code. So code
can run on 2.6 and use the feature, while running unmodified on 2.5
and earlier (not using it).
As for actual language and library changes (such as any new future
import): there was indeed little point adding them. However, given
that the possible migration paths weren't as clear back then as they
are now, it is understandable that people considered this a viable
In addition, for 2.6, it's a bit more realistic to assume that people
might drop 2.5 support and still support 2.x for some more time (in
particular as people wouldn't rule out a 2.8 release back then, either).
> Any program which must retain
> Python 2.5 compatibility will not be able to use them. Yet 2.6 is a
> more useful stepping stone towards 3.x than 2.5 is.
I disagree fairly much (except that the 3k warnings probably *are*
useful - even though I haven't ever used them myself).
> So yes, it would be quite desirable to see nonlocal and as many other
> 3.x features as possible backported for 2.7. And depending on how close
> 2.7 manages to get, it may make sense to backport anything that doesn't
> make it into 2.7 for a 2.8 release.
There might not be a 2.8 release at all, though.
> The 3.x transition is *hard*. Anything that makes it easier is good.
I agree. I question whether backporting features actually makes the
In addition, in the *specific* case: the nonlocal keyword isn't
necessary for a transition *at all*. Code that currently works without
it won't need it when ported to 3.x. You may not be able to use it while
maintaining 2.x and 3.x simultaneously, but you can certainly do the
transition just fine without it.
More information about the Python-Dev