summaryrefslogtreecommitdiff
path: root/coverage/backward.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-11-04 18:42:42 -0400
committerNed Batchelder <ned@nedbatchelder.com>2017-11-04 18:42:42 -0400
commit6f2b0f613c3770b2fe9b702ff691dd5e46c1f44d (patch)
tree2aac9f9405a98f01ba16be63d6138827e1dddb4e /coverage/backward.py
parent1523ffa9e5f26a782981409ecb784e24e074f250 (diff)
downloadpython-coveragepy-6f2b0f613c3770b2fe9b702ff691dd5e46c1f44d.tar.gz
Another approach to solving the 'dictionary changed size during iteration' problem
Diffstat (limited to 'coverage/backward.py')
-rw-r--r--coverage/backward.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 62ca495..5aff640 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -59,18 +59,29 @@ except ImportError:
# in Python versions earlier than 3.3.
from pipes import quote as shlex_quote
-# A function to iterate listlessly over a dict's items.
+# A function to iterate listlessly over a dict's items, and one to get the
+# items as a list.
try:
{}.iteritems
except AttributeError:
+ # Python 3
def iitems(d):
"""Produce the items from dict `d`."""
return d.items()
+
+ def litems(d):
+ """Return a list of items from dict `d`."""
+ return list(d.items())
else:
+ # Python 2
def iitems(d):
"""Produce the items from dict `d`."""
return d.iteritems()
+ def litems(d):
+ """Return a list of items from dict `d`."""
+ return d.items()
+
# Getting the `next` function from an iterator is different in 2 and 3.
try:
iter([]).next