Patchwork py3: switch to .items() using transformer

login
register
mail settings
Submitter Pulkit Goyal
Date Oct. 7, 2016, 1:31 p.m.
Message ID <263428cf3f19dfa62aab.1475847094@pulkit-goyal>
Download mbox | patch
Permalink /patch/16891/
State Accepted
Headers show

Comments

Pulkit Goyal - Oct. 7, 2016, 1:31 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1475846997 -7200
#      Fri Oct 07 15:29:57 2016 +0200
# Node ID 263428cf3f19dfa62aab482326ab04afd3285354
# Parent  82a0fcbb0066b96a51c6b16eec9c0384e677dee3
py3: switch to .items() using transformer

.iteritems() don't exist in Python 3 world. Used the transformer
to replace .iteritems() to .items()

Patch

diff -r 82a0fcbb0066 -r 263428cf3f19 mercurial/__init__.py
--- a/mercurial/__init__.py	Fri Oct 07 14:04:49 2016 +0200
+++ b/mercurial/__init__.py	Fri Oct 07 15:29:57 2016 +0200
@@ -305,6 +305,13 @@ 
                     except IndexError:
                         pass
 
+                # It changes iteritems to items as iteritems is not
+                # present in Python 3 world.
+                if fn == 'iteritems':
+                    yield tokenize.TokenInfo(t.type, 'items',
+                                             t.start, t.end, t.line)
+                    continue
+
             # Emit unmodified token.
             yield t
 
@@ -312,7 +319,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\x03'
+    BYTECODEHEADER = b'HG\x00\x04'
 
     class hgloader(importlib.machinery.SourceFileLoader):
         """Custom module loader that transforms source code.