[Python-Dev] nonlocal keyword in 2.x?

Michael Foord fuzzyman at voidspace.org.uk
Thu Oct 22 23:08:06 CEST 2009

Martin v. Löwis wrote:
> 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,
>>> anyway.
>> 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.
> Hmm. Really?
>> 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?

 From the Django roadmap for supporting 3.0, using 2.6 as a stepping 
stone (and if 2.7 was a *better* stepping stone then it would make it 


* First half of 2009: Django 1.1 is released, with a notification that
  it will be the final release supporting Python 2.3.

* Second half of 2009: Django 1.2 is released, drops Python 2.3
  support and is the final release supporting Python 2.4.

* First half of 2010: Django 1.3 is released, drops Python 2.4 support
  and is the final release supporting Python 2.5.

* Second half of 2010: Django 1.4 is released and drops Python 2.5

This gets us to a situation where, about a year after the release of
Python 3.0, Django will be ready to make the transition -- the only
2.x Python we'll be supporting is Python 2.6, and 2to3 plus manual
effort and available supporting libraries should make it possible to
also run Django on Python 3.0 either at that point or not long after.

 From there, 2.6 support can be dropped whenever convenient, and Django
can move to running only on Python 3.x at whatever time is judged

All the best,

Michael Foord

>> 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.
> Correct.
>> 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
> path.
> 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
> transition easier.
> 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.
> Regards,
> Martin
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk


More information about the Python-Dev mailing list