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
commit3ca6fdd609eea353f89fa7047d85d6b48f2af68f (patch)
tree2a1af73c786ddb9a34a71be7eec723a7581e4be5 /coverage/backward.py
parent9ee742b38e6610bb3290bd4680723ea47eeac181 (diff)
downloadpython-coveragepy-3ca6fdd609eea353f89fa7047d85d6b48f2af68f.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 f9402f4..cb62638 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):