Mercurial > hg
diff mercurial/__init__.py @ 43085:eef9a2d67051
py3: manually import pycompat.open into files that need it
We want to eliminate the source transformer. Currently it inserts
a `from mercurial.pycompat import ...` at the top of files to alias
some builtins.
This commit replaces the implicit import of `open` with an explicit
import on files that need it and changes the source transformer to
no longer import `open`.
As part of this, we needed to store an explicit local for `open` in
the Python 2 code path in `pycompat` so the import works. (Builtins
that are automatically in scope cannot be imported.)
Differential Revision: https://phab.mercurial-scm.org/D7005
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 06 Oct 2019 13:28:56 -0400 |
parents | 88eba7103660 |
children | bbcbb82e3589 |
line wrap: on
line diff
--- a/mercurial/__init__.py Sun Oct 06 13:17:19 2019 -0400 +++ b/mercurial/__init__.py Sun Oct 06 13:28:56 2019 -0400 @@ -172,7 +172,7 @@ l = ( b'; from mercurial.pycompat import ' b'delattr, getattr, hasattr, setattr, ' - b'open, unicode\n' + b'unicode\n' ) for u in tokenize.tokenize(io.BytesIO(l).readline): if u.type in (tokenize.ENCODING, token.ENDMARKER): @@ -221,7 +221,7 @@ # ``replacetoken`` or any mechanism that changes semantics of module # loading is changed. Otherwise cached bytecode may get loaded without # the new transformation mechanisms applied. - BYTECODEHEADER = b'HG\x00\x0c' + BYTECODEHEADER = b'HG\x00\x0d' class hgloader(importlib.machinery.SourceFileLoader): """Custom module loader that transforms source code.