From 98a7b99ed97af0f5dfc6fc7f5219ad4b026a6dfc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 28 Dec 2014 09:03:39 -0500 Subject: Move next/__next__ distinction into backward.py --- coverage/backward.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'coverage/backward.py') 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): -- cgit v1.2.1