changeset 42603:3018749a71bb

py3: source-transform only call-sites of iteritems(), not definitions branchmap.branchcache, among other classes, defines a iteritems(). That currently gets replaced by items() by the source transformer. That makes it harder for extensions to work with both py2 and py3, since they have to call either items() or iteritems() on branchcache. Let's not replace definitions of iteritems() (and itervalues()) and only replace the call-sites. We need to also add an items() alias to branchcache (etc) so our transformer call-sites will find it. Differential Revision: https://phab.mercurial-scm.org/D6641
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 12 Jul 2019 23:34:24 -0700
parents c7d236b55a3e
children 209f2b8a50dc
files hgext/remotenames.py mercurial/__init__.py mercurial/branchmap.py
diffstat 3 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/remotenames.py	Sun Jul 14 23:21:28 2019 -0700
+++ b/hgext/remotenames.py	Fri Jul 12 23:34:24 2019 -0700
@@ -167,6 +167,8 @@
         for k, vtup in self.potentialentries.iteritems():
             yield (k, [bin(vtup[0])])
 
+    items = iteritems
+
 class remotenames(object):
     """
     This class encapsulates all the remotenames state. It also contains
--- a/mercurial/__init__.py	Sun Jul 14 23:21:28 2019 -0700
+++ b/mercurial/__init__.py	Fri Jul 12 23:34:24 2019 -0700
@@ -225,7 +225,9 @@
 
                 # It changes iteritems/values to items/values as they are not
                 # present in Python 3 world.
-                elif fn in ('iteritems', 'itervalues'):
+                elif (fn in ('iteritems', 'itervalues') and
+                      not (tokens[i - 1].type == token.NAME and
+                           tokens[i - 1].string == 'def')):
                     yield t._replace(string=fn[4:])
                     continue
 
@@ -236,7 +238,7 @@
     # ``replacetoken`` or any mechanism that changes semantics of module
     # loading is changed. Otherwise cached bytecode may get loaded without
     # the new transformation mechanisms applied.
-    BYTECODEHEADER = b'HG\x00\x0b'
+    BYTECODEHEADER = b'HG\x00\x0c'
 
     class hgloader(importlib.machinery.SourceFileLoader):
         """Custom module loader that transforms source code.
--- a/mercurial/branchmap.py	Sun Jul 14 23:21:28 2019 -0700
+++ b/mercurial/branchmap.py	Fri Jul 12 23:34:24 2019 -0700
@@ -218,6 +218,8 @@
             self._verifybranch(k)
             yield k, v
 
+    items = iteritems
+
     def hasbranch(self, label):
         """ checks whether a branch of this name exists or not """
         self._verifybranch(label)