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

Giampaolo Rodolà g.rodola at gmail.com
Sat Oct 8 18:57:47 CEST 2011


Hello everybody,
at work we're using different versions of python, from 2.4 to 2.7.
Because of the differences between the various versions in terms of
features we have a "util.pycompat" module which basically is a copy &
paste of different features which were added to stdlib in every new
major version throughout the years.
What we do is basically this.
Instead of:

from collections import namedtuple, OrderedDict
import fractions

...we do:

from util.pycompat.collections import namedtuple, OrderedDict
from util.pycompat import fractions  # py 2.6
from util.pycompat.builtins import all, any  # py 2.5
# etc...

This let us use different stdlib features which appeared in latest
Python versions (including 3.2) throughout all our code base.
Now, what I have in mind is to release this as a public module so that
everyone who cannot upgrade to a recent python version can benefit of
newer features.
By taking a quick look at the various "what's new" documents this is a
brief list of what this module would include:

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)

I have a couple of doubts about this though.
The first one is about licensing.
What I would be doing is basically copy & paste pieces of the python
stdlib modules (including tests) and, where needed, adjust them so
that they work with older python versions.
Would this represent problem?

My second doubt is about morality.
Although this might be useful to those people who are forced to use
older python versions, on the other hand it might represent an
incentive for not upgrading (and there will be python 3.X features as
well).
Or maybe it won't, I don't know, point is I feel kind of guilty. =)

I'd like to hear your opinions, especially about the second point.


Best regards,

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/


More information about the Python-Dev mailing list