Patchwork D6641: py3: source-transform only call-sites of iteritems(), not definitions

login
register
mail settings
Submitter phabricator
Date July 13, 2019, 7:11 a.m.
Message ID <differential-rev-PHID-DREV-ely7ys4bju4xcfkqap7o-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/40918/
State Superseded
Headers show

Comments

phabricator - July 13, 2019, 7:11 a.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/remotenames.py
  mercurial/__init__.py
  mercurial/branchmap.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - July 15, 2019, 11:38 p.m.
> --- a/mercurial/__init__.py
> +++ b/mercurial/__init__.py
> @@ -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')):

Perhaps, we need to bump the BYTECODEHEADER version to recompile all
py3 modules.
phabricator - July 15, 2019, 11:39 p.m.
yuja added a comment.


  > - a/mercurial/__init__.py
  >
  > +++ b/mercurial/__init__.py
  > @@ -225,7 +225,9 @@
  >
  >   1. It changes iteritems/values to items/values as they are not
  >   2. 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')):
  
  Perhaps, we need to bump the BYTECODEHEADER version to recompile all
  py3 modules.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6641/new/

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

To: martinvonz, #hg-reviewers, pulkit
Cc: yuja, mercurial-devel
phabricator - July 15, 2019, 11:42 p.m.
martinvonz added a comment.


  In D6641#97205 <https://phab.mercurial-scm.org/D6641#97205>, @yuja wrote:
  
  >> - a/mercurial/__init__.py
  >>
  >> +++ b/mercurial/__init__.py
  >> @@ -225,7 +225,9 @@
  >>
  >>   1. It changes iteritems/values to items/values as they are not
  >>   2. 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')):
  >
  > Perhaps, we need to bump the BYTECODEHEADER version to recompile all
  > py3 modules.
  
  Oops, I missed that despite the the big all-caps message. Thanks for pointing that out. I'll fix it in flight (changing `HG\x00\x0b` to `HG\x00\x0c`).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6641/new/

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

To: martinvonz, #hg-reviewers, pulkit
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -212,6 +212,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)
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -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
 
diff --git a/hgext/remotenames.py b/hgext/remotenames.py
--- a/hgext/remotenames.py
+++ b/hgext/remotenames.py
@@ -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