summaryrefslogtreecommitdiff
path: root/coverage/backward.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-12-28 09:03:39 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-12-28 09:03:39 -0500
commit98a7b99ed97af0f5dfc6fc7f5219ad4b026a6dfc (patch)
tree48a18f35dbf2805f5c7f9952859d5014fb63a16b /coverage/backward.py
parent228c5a07e04eda70074ce40b25512700f5168dc4 (diff)
downloadpython-coveragepy-git-98a7b99ed97af0f5dfc6fc7f5219ad4b026a6dfc.tar.gz
Move next/__next__ distinction into backward.py
Diffstat (limited to 'coverage/backward.py')
-rw-r--r--coverage/backward.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index f9402f41..cb62638a 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -52,6 +52,18 @@ else:
"""Produce the items from dict `d`."""
return d.iteritems()
+# Getting the `next` function from an iterator is different in 2 and 3.
+try:
+ iter([]).next
+except AttributeError:
+ def iternext(seq):
+ """Get the `next` function for iterating over `seq`."""
+ return iter(seq).__next__
+else:
+ def iternext(seq):
+ """Get the `next` function for iterating over `seq`."""
+ return iter(seq).next
+
# Python 3.x is picky about bytes and strings, so provide methods to
# get them right, and make them no-ops in 2.x
if sys.version_info >= (3, 0):