iterators.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """
  2. This module is designed to be used as follows::
  3. from future.builtins.iterators import *
  4. And then, for example::
  5. for i in range(10**15):
  6. pass
  7. for (a, b) in zip(range(10**15), range(-10**15, 0)):
  8. pass
  9. Note that this is standard Python 3 code, plus some imports that do
  10. nothing on Python 3.
  11. The iterators this brings in are::
  12. - ``range``
  13. - ``filter``
  14. - ``map``
  15. - ``zip``
  16. On Python 2, ``range`` is a pure-Python backport of Python 3's ``range``
  17. iterator with slicing support. The other iterators (``filter``, ``map``,
  18. ``zip``) are from the ``itertools`` module on Python 2. On Python 3 these
  19. are available in the module namespace but not exported for * imports via
  20. __all__ (zero no namespace pollution).
  21. Note that these are also available in the standard library
  22. ``future_builtins`` module on Python 2 -- but not Python 3, so using
  23. the standard library version is not portable, nor anywhere near complete.
  24. """
  25. from __future__ import division, absolute_import, print_function
  26. import itertools
  27. from future import utils
  28. if not utils.PY3:
  29. filter = itertools.ifilter
  30. map = itertools.imap
  31. from future.types import newrange as range
  32. zip = itertools.izip
  33. __all__ = ['filter', 'map', 'range', 'zip']
  34. else:
  35. import builtins
  36. filter = builtins.filter
  37. map = builtins.map
  38. range = builtins.range
  39. zip = builtins.zip
  40. __all__ = []