# HG changeset patch # User Martin von Zweigbergk # Date 2019-07-13 06:34:24 # Node ID 5a6ba316573673be536895e38fcd2edb89a5a6c6 # Parent c7d236b55a3ebc82b527d759cd41550e689b6e39 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 diff --git a/hgext/remotenames.py b/hgext/remotenames.py --- a/hgext/remotenames.py +++ b/hgext/remotenames.py @@ -167,6 +167,8 @@ class lazyremotenamedict(mutablemapping) 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 diff --git a/mercurial/__init__.py b/mercurial/__init__.py --- a/mercurial/__init__.py +++ b/mercurial/__init__.py @@ -225,7 +225,9 @@ if sys.version_info[0] >= 3: # 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/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -218,6 +218,8 @@ class branchcache(object): 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)