Patchwork D2164: py3: avoid changing dictionary during iteration

login
register
mail settings
Submitter phabricator
Date Feb. 12, 2018, 2:36 a.m.
Message ID <differential-rev-PHID-DREV-6y55n65zdd2xqfmwwxic-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27630/
State Superseded
Headers show

Comments

phabricator - Feb. 12, 2018, 2:36 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  dict.items() and friends are iterators/views in Python 3. You
  aren't allowed to mutate the underlying dictionary when iterating
  on these views. So iterate over a copy of things.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2164

AFFECTED FILES
  mercurial/copies.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -123,7 +123,7 @@ 
             t[k] = v
 
     # remove criss-crossed copies
-    for k, v in t.items():
+    for k, v in list(t.items()):
         if k in src and v in dst:
             del t[k]