Issue 19363: Python 2.7's future_builtins.map is not compatible with Python 3's map (original) (raw)

In Python 2.7, future_builtins.map accepts None as its first (function) argument:

Python 2.7.5 (default, Aug  1 2013, 01:01:17) 
>>> from future_builtins import map
>>> list(map(None, range(3), 'ABC'))
[(0, 'A'), (1, 'B'), (2, 'C')]

But in Python 3.x, map does not accept None as its first argument:

Python 3.3.2 (default, May 21 2013, 11:50:47) 
>>> list(map(None, range(3), 'ABC'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

The documentation says, "if you want to write code compatible with Python 3 builtins, import them from this module," so this incompatibility may give Python 2.7 programmers the false impression that a program which uses map(None, ...) is portable to Python 3.

I suggest that future_builtins.map in Python 2.7 should behave the same as map in Python 3: that is, it should raise a TypeError if None was passed as the first argument.

Sorry about that; here it is. I had second thoughts about recommending zip() as an alternative (that would only work for cases where the None was constant; in other cases you might need lambda *args: args, but this seemed too complicated), so the note now says only:

Note: In Python 3, map() does not accept None for the
function argument.