[gyb] Convert map object to list object

Python 2's map function [1] returns a list by default. Compared with
Python 3's map function [2] which returns an iterator (or map object).
The former is subscriptable, while the latter is not.

This patch explicitly converts the result of some map operations to be
a list. That way they have the same intended behaviour on both Python 2
and 3.

[1] https://docs.python.org/2/library/functions.html#map
[2] https://docs.python.org/3/library/functions.html#map
This commit is contained in:
Ryan Lovelett
2015-12-30 11:10:52 -05:00
parent c8e74d1ba1
commit 360c2b2bbc

View File

@@ -331,7 +331,10 @@ class UnicodeTrieGenerator(object):
else:
return idx
return map(map_index, indexes)
# NOTE: Python 2's `map` function returns a list. Where Python 3's
# `map` function returns an iterator. To work around this the
# result of the `map` is explicitly converted to a `list`.
return list(map(map_index, indexes))
# If self.BMP_data contains identical data blocks, keep the first one,
# remove duplicates and change the indexes in self.BMP_lookup to point to