diff hgext/remotefilelog/shallowutil.py @ 43892:649d3ac37a12

py3: define and use pycompat.iteritems() for hgext/ .iteritems() -> .items() is the last source transform being performed. But it is also the most widely used. This commit adds a pycompat.iteritems symbol and imports it in place of .iteritems() for usage in hgext/. I chose to stop at just hgext/ because the patch will be large and it is an easy boundary to stop at since we can disable source transformation on a per-package basis. There are places where the type does implement items() and we could call items() directly. However, this would require critical thought and I thought it would be easier to just blindly change the code. We know which call sites need to be audited in the future because they have "pycompat.iteritems." With this change, we no longer perform source transformation on hgext! Differential Revision: https://phab.mercurial-scm.org/D7014
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Oct 2019 19:25:18 -0400 (2019-10-06)
parents eef9a2d67051
children 8ff1ecfadcd1
line wrap: on
line diff
--- a/hgext/remotefilelog/shallowutil.py
+++ b/hgext/remotefilelog/shallowutil.py
@@ -103,7 +103,7 @@
     """
     result = collections.defaultdict(lambda: 0)
     for dict in dicts:
-        for k, v in dict.iteritems():
+        for k, v in pycompat.iteritems(dict):
             result[k] += v
     return result
 
@@ -111,7 +111,7 @@
 def prefixkeys(dict, prefix):
     """Returns ``dict`` with ``prefix`` prepended to all its keys."""
     result = {}
-    for k, v in dict.iteritems():
+    for k, v in pycompat.iteritems(dict):
         result[prefix + k] = v
     return result
 
@@ -160,7 +160,7 @@
     length limit is exceeded
     """
     metabuf = b''
-    for k, v in sorted((metadict or {}).iteritems()):
+    for k, v in sorted(pycompat.iteritems((metadict or {}))):
         if len(k) != 1:
             raise error.ProgrammingError(b'packmeta: illegal key: %s' % k)
         if len(v) > 0xFFFE:
@@ -188,7 +188,7 @@
     and METAKEYFLAG will be dropped if its value is 0.
     """
     newmeta = {}
-    for k, v in (metadict or {}).iteritems():
+    for k, v in pycompat.iteritems(metadict or {}):
         expectedtype = _metaitemtypes.get(k, (bytes,))
         if not isinstance(v, expectedtype):
             raise error.ProgrammingError(b'packmeta: wrong type of key %s' % k)
@@ -209,7 +209,7 @@
     integers.
     """
     metadict = _parsepackmeta(metabuf)
-    for k, v in metadict.iteritems():
+    for k, v in pycompat.iteritems(metadict):
         if k in _metaitemtypes and int in _metaitemtypes[k]:
             metadict[k] = bin2int(v)
     return metadict