From patchwork Mon May 29 14:29:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 2, manifest-py3] cleanup: rename all iteritems methods to items and add iteritems alias From: Augie Fackler X-Patchwork-Id: 21040 Message-Id: <5f4c7324c8edd5e82f71.1496068190@imladris.local> To: mercurial-devel@mercurial-scm.org Date: Mon, 29 May 2017 10:29:50 -0400 # HG changeset patch # User Augie Fackler # Date 1496030402 14400 # Mon May 29 00:00:02 2017 -0400 # Node ID 5f4c7324c8edd5e82f719bbef6a55ec24560ea2b # Parent aa333c1982abfe12a3940811d07468a286de93db cleanup: rename all iteritems methods to items and add iteritems alias Due to a quirk of our module importer setup on Python 3, all calls and definitions of methods named iteritems() get rewritten at import time. Unfortunately, this means there's not a good portable way to access these methods from non-module-loader'ed code like our unit tests. This change fixes that, which also unblocks test-manifest.py from passing under Python 3. We don't presently define any itervalues methods, or we'd need to give those similar treatment. diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -343,9 +343,11 @@ class dirstate(object): for x in sorted(self._map): yield x - def iteritems(self): + def items(self): return self._map.iteritems() + iteritems = items + def parents(self): return [self._validate(p) for p in self._pl] diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -579,9 +579,11 @@ class manifestdict(object): c._lm = self._lm.copy() return c - def iteritems(self): + def items(self): return (x[:2] for x in self._lm.iterentries()) + iteritems = items + def iterentries(self): return self._lm.iterentries() @@ -788,7 +790,7 @@ class treemanifest(object): for x in n.iterentries(): yield x - def iteritems(self): + def items(self): self._load() for p, n in sorted(itertools.chain(self._dirs.items(), self._files.items())): @@ -798,6 +800,8 @@ class treemanifest(object): for f, sn in n.iteritems(): yield f, sn + iteritems = items + def iterkeys(self): self._load() for p in sorted(itertools.chain(self._dirs, self._files)): diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py --- a/mercurial/namespaces.py +++ b/mercurial/namespaces.py @@ -66,9 +66,11 @@ class namespaces(object): def __iter__(self): return self._names.__iter__() - def iteritems(self): + def items(self): return self._names.iteritems() + iteritems = items + def addnamespace(self, namespace, order=None): """register a namespace