comparison mercurial/__init__.py @ 38785:fb9121ea38c4

py3: stop rewriting xrange() to pycompat.xrange() We now require the use of pycompat.xrange() in source. One less feature in the module importer gets us one step closer to Python 3 native source code. Differential Revision: https://phab.mercurial-scm.org/D4034
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 01 Aug 2018 13:10:07 -0700
parents 5246f940a48e
children 4277e20cfec4
comparison
equal deleted inserted replaced
38784:882ef6949bdc 38785:fb9121ea38c4
180 if fullname == 'mercurial.pycompat': 180 if fullname == 'mercurial.pycompat':
181 yield t 181 yield t
182 continue 182 continue
183 r, c = t.start 183 r, c = t.start
184 l = (b'; from mercurial.pycompat import ' 184 l = (b'; from mercurial.pycompat import '
185 b'delattr, getattr, hasattr, setattr, xrange, ' 185 b'delattr, getattr, hasattr, setattr, '
186 b'open, unicode\n') 186 b'open, unicode\n')
187 for u in tokenize.tokenize(io.BytesIO(l).readline): 187 for u in tokenize.tokenize(io.BytesIO(l).readline):
188 if u.type in (tokenize.ENCODING, token.ENDMARKER): 188 if u.type in (tokenize.ENCODING, token.ENDMARKER):
189 continue 189 continue
190 yield u._replace( 190 yield u._replace(
221 221
222 # Header to add to bytecode files. This MUST be changed when 222 # Header to add to bytecode files. This MUST be changed when
223 # ``replacetoken`` or any mechanism that changes semantics of module 223 # ``replacetoken`` or any mechanism that changes semantics of module
224 # loading is changed. Otherwise cached bytecode may get loaded without 224 # loading is changed. Otherwise cached bytecode may get loaded without
225 # the new transformation mechanisms applied. 225 # the new transformation mechanisms applied.
226 BYTECODEHEADER = b'HG\x00\x0a' 226 BYTECODEHEADER = b'HG\x00\x0b'
227 227
228 class hgloader(importlib.machinery.SourceFileLoader): 228 class hgloader(importlib.machinery.SourceFileLoader):
229 """Custom module loader that transforms source code. 229 """Custom module loader that transforms source code.
230 230
231 When the source code is converted to a code object, we transform 231 When the source code is converted to a code object, we transform