Fri 30 Jun 2006
I’ve recently set out to check off a number of the “remove x, y and z” items from PEP 3100, which details “miscellaneous Python 3.0 plans”. My latest of these was removing reduce(), map() and filter() from the built-in namespace.
The biggest hurdle wasn’t removing them a the C level; that took about 45 seconds. The main issue — which ended up taking 4 or 5 hours — was rewriting every single usage of map(), filter() and reduce() in the standard library. map() and filter() were pretty easy: you just change them to list comprehensions. reduce(), on the other hand, was a something else.
See, reduce() isn’t used that often in the stdlib, but when it is, it’s generally used in some hideous combination with map() and filter() that makes it extremely time consuming to rewrite. What makes this even better is that these chunks of code are usually in places without test coverage, meaning there’s no easy way to verify that what I’ve done is right.
To make life easier for large projects that make heavy use of map() and friends, I’m adding a functional.bwcompat submodule to functional. This will contain map(), reduce(), filter() and any other functional programming-related tools that will get kicked out of mainline Python come the 3.0 release. All you’ll need to do to make your code work is a simple
from functional.bwcompat import map, reduce, filter
and everything will work as before.
functional.bwcompat will make its debut in functional’s 0.7 release.