ponty / PyVirtualDisplay

Python wrapper for Xvfb, Xephyr and Xvnc
BSD 2-Clause "Simplified" License
709 stars 78 forks source link

Cast map() -> list to support Py2/3, allows len(ls) to work for Python 3 w/o breaking Python 2 #24

Closed autumnjolitz closed 7 years ago

autumnjolitz commented 7 years ago

map() in Python 3 is a lazy generator, meaning it has no length. In Python 2, map() produced a list which does possess a length.

Without this change, the example in the README.rst fails on OSX/XQuartz Python 3.6 installation.

This PR casts the map() generator to a list.

Proof that this is of negligible penalty:

 (cpython36) benjolitz-laptop:~/software/PyVirtualDisplay [master]$ python -m timeit -s 'item = []' 'item = list(item)'
10000000 loops, best of 3: 0.182 usec per loop

I don't think anyone will cry about losing 0.182 microseconds. They might cry about pyvirtualdisplay throwing a TypeError: object of type 'map' has no len()

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 84.722% when pulling 23343af4a857223f3d1da11d00d14ae6061eb4dd on benjolitz:master into da6544e4bd8974cb3af9a61538ebcd17344bce30 on ponty:master.

ponty commented 7 years ago

Thanks