diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-11-04 18:42:42 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-11-04 18:42:42 -0400 |
commit | 6f2b0f613c3770b2fe9b702ff691dd5e46c1f44d (patch) | |
tree | 2aac9f9405a98f01ba16be63d6138827e1dddb4e /coverage/backward.py | |
parent | 1523ffa9e5f26a782981409ecb784e24e074f250 (diff) | |
download | python-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.py | 13 |
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 |