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 | 781fe6a219e1b643c24a8612fea4c8f4fb458267 (patch) | |
tree | 8a657fcf7bacf1d10c17b4c58e3432d0e4c415da /coverage/backward.py | |
parent | fd6c77243dfa7f6ac1c9d5898195bde445d05eac (diff) | |
download | python-coveragepy-git-781fe6a219e1b643c24a8612fea4c8f4fb458267.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 62ca495f..5aff6406 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 |