Это ошибка в их реализации map
. Вот их код для этого:
def oldmap(func, *iterables):
"""
map(function, sequence[, sequence, ...]) -> list
Return a list of the results of applying the function to the
items of the argument sequence(s). If more than one sequence is
given, the function is called with an argument list consisting of
the corresponding item of each sequence, substituting None for
missing values when not all sequences have the same length. If
the function is None, return a list of the items of the sequence
(or a list of tuples if more than one sequence).
Test cases:
>>> oldmap(None, 'hello world')
['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
>>> oldmap(None, range(4))
[0, 1, 2, 3]
More test cases are in past.tests.test_builtins.
"""
zipped = itertools.zip_longest(*iterables)
l = list(zipped)
if len(l) == 0:
return []
if func is None:
result = l
else:
result = list(starmap(func, l))
# Inspect to see whether it's a simple sequence of tuples
try:
if max([len(item) for item in result]) == 1:
return list(chain.from_iterable(result))
# return list(flatmap(func, result))
except TypeError as e:
# Simple objects like ints have no len()
pass
return result
Ошибка, где говорится:
# Inspect to see whether it's a simple sequence of tuples
В их реализации, если вызываемый объект возвращает список объектов с len
из затем они «распаковываются» и возвращается плоский список. Хотя я не уверен, откуда это взялось, поскольку, насколько я знаю, Python 2 не делал этого даже для кортежей:
# Python 2
print(map(lambda x: (x,), [1, 2]))
# [(1,), (2,)]
Кажется, что открыт сообщите об этом в хранилище кода библиотеки, если вы хотите следовать этому.