Mercurial > hg
comparison mercurial/namespaces.py @ 43106:d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
This commit finishes porting .iteritems() to pycompat.iteritems()
for the mercurial package.
The translation of .iteritems() to .items() was the last conversion
performed by the source transformer. With the porting to pycompat
complete, we no longer have a need for the source transformer. So
the source transformer has been removed. Good riddance! The code
base is now compatible with Python 2 and Python 3.
For the record, as the person who introduced the source transformer,
it brings me joy to delete it. It accomplished its goal to facilitate
a port to Python 3 without overly burdening people on some painful
low-level differences between Python 2 and 3. It is unfortunate we
still have to wallpaper over many differences with the pycompat
shim. But it is what it is.
Differential Revision: https://phab.mercurial-scm.org/D7015
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 00:04:04 -0400 |
parents | 687b865b95ad |
children | 59ad165f6cdb |
comparison
equal
deleted
inserted
replaced
43105:649d3ac37a12 | 43106:d783f945a701 |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import |
2 | 2 |
3 from .i18n import _ | 3 from .i18n import _ |
4 from . import ( | 4 from . import ( |
5 pycompat, | |
5 registrar, | 6 registrar, |
6 templatekw, | 7 templatekw, |
7 util, | 8 util, |
8 ) | 9 ) |
9 | 10 |
81 | 82 |
82 def __iter__(self): | 83 def __iter__(self): |
83 return self._names.__iter__() | 84 return self._names.__iter__() |
84 | 85 |
85 def items(self): | 86 def items(self): |
86 return self._names.iteritems() | 87 return pycompat.iteritems(self._names) |
87 | 88 |
88 iteritems = items | 89 iteritems = items |
89 | 90 |
90 def addnamespace(self, namespace, order=None): | 91 def addnamespace(self, namespace, order=None): |
91 """register a namespace | 92 """register a namespace |
114 by the namespace's singlenode() function. The first match returned by | 115 by the namespace's singlenode() function. The first match returned by |
115 a namespace in the defined precedence order is used. | 116 a namespace in the defined precedence order is used. |
116 | 117 |
117 Raises a KeyError if there is no such node. | 118 Raises a KeyError if there is no such node. |
118 """ | 119 """ |
119 for ns, v in self._names.iteritems(): | 120 for ns, v in pycompat.iteritems(self._names): |
120 n = v.singlenode(repo, name) | 121 n = v.singlenode(repo, name) |
121 if n: | 122 if n: |
122 return n | 123 return n |
123 raise KeyError(_(b'no such name: %s') % name) | 124 raise KeyError(_(b'no such name: %s') % name) |
124 | 125 |