[Python-Dev] Bring new features to older python versions

Toshio Kuratomi a.badger at gmail.com
Sat Oct 8 21:47:01 CEST 2011


I have some similar code in kitchen:
http://packages.python.org/kitchen/api-overview.html

It wasn't as ambitious as your initial goals sound (I was only working on
pulling out what was necessary for what people requested rather than an
all-inclusive set of changes).  You're welcome to join me and work on this
aspect of kitchen if you'd like or you can go your own way and I'll probably
start pointing people at your library (Like I do with hashlib, bunch,
iterutils, ordereddict, etc).

I have a need to support a small amount of code as far back as python-2.3
I don't suppose you're interested in that as well? ;-)

On Sat, Oct 08, 2011 at 06:57:47PM +0200, Giampaolo Rodolà wrote:
> functools (2.5)
> any, all builtins (2.5)
> collections.defaultdict (2.5)
> property setters/deleters (2.6)
> abc (2.6)
> fractions (2.6)
> collections.OrderedDict (2.7)
> collections.Counter (2.7)
> unittest2 (2.7)
> functools.lru_cache (3.2)
> functools.total_ordering (3.2)
> itertools.accumulate (3.2)
> reprlib (3.2)
> contextlib.ContextDecorator (3.2)
> 

You can also add subprocess to this list.  There's various methods and
functions that were added to subprocess since it's first appearance in
python-2.4 (Check the library docs page for notes about this [1] _)

hashlib (which has a pypi backport already) is another one.

hmac is a third which you probably won't notice if you're just perusing
docs.  It's an issue because if someone tries to use the stdlib's hmac 
together with the pypi hashlib, hmac will fail unless it's from a recent enough
python.

.. [1]_:: http://docs.python.org/library/subprocess.html


Speaking as someone who works on a Linux distribution, one thing that I'd
appreciate is if you could take care to make it so the copied code doesn't
get used if the stdlib already provides the necessary code.  If you do this,
it makes it easier for people who have to audit the code to do their jobs.
Instead of having to check every consumer of the compat library to make sure
they use something like this::

try:
    import functools
except ImportError:
    from pycompat import functools
import sys

if sys.version_info >= (2, 5):
    import hmac
else:
   from pycompat import hmac


You can depend on roughly the same logic having been performed in the
library itself which greatly eases their burden.  You can look at the
kitchen pycompat code for some examples of doing this [2]_.

.. [2]_ http://bzr.fedorahosted.org/bzr/kitchen/devel/files/head:/kitchen/

-Toshio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20111008/d8644f23/attachment-0001.pgp>


More information about the Python-Dev mailing list