D7005: py3: manually import pycompat.open into files that need it

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sun Oct 6 17:34:16 EDT 2019


indygreg created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: martinvonz.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7005

AFFECTED FILES
  hgext/churn.py
  hgext/convert/common.py
  hgext/convert/convcmd.py
  hgext/convert/cvs.py
  hgext/convert/cvsps.py
  hgext/convert/hg.py
  hgext/convert/monotone.py
  hgext/convert/subversion.py
  hgext/fastannotate/context.py
  hgext/fastannotate/protocol.py
  hgext/fastannotate/revmap.py
  hgext/fsmonitor/__init__.py
  hgext/histedit.py
  hgext/infinitepush/__init__.py
  hgext/infinitepush/store.py
  hgext/largefiles/lfutil.py
  hgext/largefiles/localstore.py
  hgext/largefiles/overrides.py
  hgext/largefiles/proto.py
  hgext/mq.py
  hgext/patchbomb.py
  hgext/rebase.py
  hgext/releasenotes.py
  hgext/relink.py
  hgext/remotefilelog/__init__.py
  hgext/remotefilelog/basepack.py
  hgext/remotefilelog/basestore.py
  hgext/remotefilelog/debugcommands.py
  hgext/remotefilelog/remotefilelogserver.py
  hgext/remotefilelog/shallowutil.py
  hgext/transplant.py
  mercurial/__init__.py
  mercurial/archival.py
  mercurial/changegroup.py
  mercurial/cmdutil.py
  mercurial/commands.py
  mercurial/context.py
  mercurial/crecord.py
  mercurial/debugcommands.py
  mercurial/extensions.py
  mercurial/filemerge.py
  mercurial/hgweb/common.py
  mercurial/hgweb/server.py
  mercurial/httpconnection.py
  mercurial/mail.py
  mercurial/match.py
  mercurial/patch.py
  mercurial/posix.py
  mercurial/profiling.py
  mercurial/pycompat.py
  mercurial/server.py
  mercurial/shelve.py
  mercurial/statprof.py
  mercurial/streamclone.py
  mercurial/subrepo.py
  mercurial/ui.py
  mercurial/util.py
  mercurial/utils/procutil.py

CHANGE DETAILS

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -20,6 +20,7 @@
 import time
 
 from ..i18n import _
+from ..pycompat import open
 
 from .. import (
     encoding,
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -35,6 +35,7 @@
 import warnings
 
 from .thirdparty import attr
+from .pycompat import open
 from hgdemandimport import tracing
 from . import (
     encoding,
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -22,6 +22,7 @@
 
 from .i18n import _
 from .node import hex
+from .pycompat import open
 
 from . import (
     color,
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -19,6 +19,7 @@
 import xml.dom.minidom
 
 from .i18n import _
+from .pycompat import open
 from . import (
     cmdutil,
     encoding,
diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -12,6 +12,7 @@
 import struct
 
 from .i18n import _
+from .pycompat import open
 from .interfaces import repository
 from . import (
     cacheutil,
diff --git a/mercurial/statprof.py b/mercurial/statprof.py
--- a/mercurial/statprof.py
+++ b/mercurial/statprof.py
@@ -114,6 +114,7 @@
 import threading
 import time
 
+from .pycompat import open
 from . import (
     encoding,
     pycompat,
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -28,6 +28,7 @@
 import stat
 
 from .i18n import _
+from .pycompat import open
 from . import (
     bookmarks,
     bundle2,
diff --git a/mercurial/server.py b/mercurial/server.py
--- a/mercurial/server.py
+++ b/mercurial/server.py
@@ -10,6 +10,7 @@
 import os
 
 from .i18n import _
+from .pycompat import open
 
 from . import (
     chgserver,
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -354,6 +354,7 @@
     sysstr = identity
     strurl = identity
     bytesurl = identity
+    open = open
 
     # this can't be parsed on Python 3
     exec(b'def raisewithtb(exc, tb):\n' b'    raise exc, None, tb\n')
diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -10,6 +10,7 @@
 import contextlib
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -21,6 +21,7 @@
 import unicodedata
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -24,6 +24,7 @@
     hex,
     short,
 )
+from .pycompat import open
 from . import (
     copies,
     diffhelper,
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -13,6 +13,7 @@
 import re
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -19,6 +19,7 @@
 import time
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
diff --git a/mercurial/httpconnection.py b/mercurial/httpconnection.py
--- a/mercurial/httpconnection.py
+++ b/mercurial/httpconnection.py
@@ -13,6 +13,7 @@
 import os
 
 from .i18n import _
+from .pycompat import open
 from . import (
     pycompat,
     util,
diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -17,6 +17,7 @@
 import wsgiref.validate
 
 from ..i18n import _
+from ..pycompat import open
 
 from .. import (
     encoding,
diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -14,6 +14,7 @@
 import os
 import stat
 
+from ..pycompat import open
 from .. import (
     encoding,
     pycompat,
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -18,6 +18,7 @@
     nullid,
     short,
 )
+from .pycompat import open
 
 from . import (
     encoding,
diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -18,6 +18,7 @@
     _,
     gettext,
 )
+from .pycompat import open
 
 from . import (
     cmdutil,
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -32,6 +32,7 @@
     nullrev,
     short,
 )
+from .pycompat import open
 from . import (
     bundle2,
     changegroup,
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -16,6 +16,7 @@
 import signal
 
 from .i18n import _
+from .pycompat import open
 from . import (
     encoding,
     error,
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -23,6 +23,7 @@
     wdirfilenodeids,
     wdirhex,
 )
+from .pycompat import open
 from . import (
     copies,
     dagop,
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -22,6 +22,7 @@
     wdirhex,
     wdirrev,
 )
+from .pycompat import open
 from . import (
     archival,
     bookmarks,
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -19,6 +19,7 @@
     nullrev,
     short,
 )
+from .pycompat import open
 
 from . import (
     bookmarks,
diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -18,6 +18,7 @@
     nullrev,
     short,
 )
+from .pycompat import open
 
 from . import (
     error,
diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -17,6 +17,7 @@
 
 from .i18n import _
 from .node import nullrev
+from .pycompat import open
 
 from . import (
     error,
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -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.
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -18,6 +18,7 @@
 import os
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     bundlerepo,
     cmdutil,
diff --git a/hgext/remotefilelog/shallowutil.py b/hgext/remotefilelog/shallowutil.py
--- a/hgext/remotefilelog/shallowutil.py
+++ b/hgext/remotefilelog/shallowutil.py
@@ -15,6 +15,7 @@
 import tempfile
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     node,
diff --git a/hgext/remotefilelog/remotefilelogserver.py b/hgext/remotefilelog/remotefilelogserver.py
--- a/hgext/remotefilelog/remotefilelogserver.py
+++ b/hgext/remotefilelog/remotefilelogserver.py
@@ -14,6 +14,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import bin, hex, nullid
+from mercurial.pycompat import open
 from mercurial import (
     changegroup,
     changelog,
diff --git a/hgext/remotefilelog/debugcommands.py b/hgext/remotefilelog/debugcommands.py
--- a/hgext/remotefilelog/debugcommands.py
+++ b/hgext/remotefilelog/debugcommands.py
@@ -12,6 +12,7 @@
 
 from mercurial.node import bin, hex, nullid, short
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     filelog,
diff --git a/hgext/remotefilelog/basestore.py b/hgext/remotefilelog/basestore.py
--- a/hgext/remotefilelog/basestore.py
+++ b/hgext/remotefilelog/basestore.py
@@ -9,6 +9,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import bin, hex
+from mercurial.pycompat import open
 from mercurial import (
     error,
     pycompat,
diff --git a/hgext/remotefilelog/basepack.py b/hgext/remotefilelog/basepack.py
--- a/hgext/remotefilelog/basepack.py
+++ b/hgext/remotefilelog/basepack.py
@@ -9,6 +9,7 @@
 import time
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     node as nodemod,
     policy,
diff --git a/hgext/remotefilelog/__init__.py b/hgext/remotefilelog/__init__.py
--- a/hgext/remotefilelog/__init__.py
+++ b/hgext/remotefilelog/__init__.py
@@ -132,6 +132,7 @@
 
 from mercurial.node import hex
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     changegroup,
     changelog,
diff --git a/hgext/relink.py b/hgext/relink.py
--- a/hgext/relink.py
+++ b/hgext/relink.py
@@ -12,6 +12,7 @@
 import stat
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     hg,
diff --git a/hgext/releasenotes.py b/hgext/releasenotes.py
--- a/hgext/releasenotes.py
+++ b/hgext/releasenotes.py
@@ -18,6 +18,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     config,
     error,
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -24,6 +24,7 @@
     nullrev,
     short,
 )
+from mercurial.pycompat import open
 from mercurial import (
     bookmarks,
     cmdutil,
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -83,6 +83,7 @@
 import socket
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     cmdutil,
     commands,
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -76,6 +76,7 @@
     nullrev,
     short,
 )
+from mercurial.pycompat import open
 from mercurial import (
     cmdutil,
     commands,
diff --git a/hgext/largefiles/proto.py b/hgext/largefiles/proto.py
--- a/hgext/largefiles/proto.py
+++ b/hgext/largefiles/proto.py
@@ -8,6 +8,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 
 from mercurial import (
     error,
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -14,6 +14,8 @@
 
 from mercurial.i18n import _
 
+from mercurial.pycompat import open
+
 from mercurial.hgweb import webcommands
 
 from mercurial import (
diff --git a/hgext/largefiles/localstore.py b/hgext/largefiles/localstore.py
--- a/hgext/largefiles/localstore.py
+++ b/hgext/largefiles/localstore.py
@@ -10,6 +10,7 @@
 from __future__ import absolute_import
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import util
 
 from . import (
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -16,6 +16,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import hex
+from mercurial.pycompat import open
 
 from mercurial import (
     dirstate,
diff --git a/hgext/infinitepush/store.py b/hgext/infinitepush/store.py
--- a/hgext/infinitepush/store.py
+++ b/hgext/infinitepush/store.py
@@ -11,6 +11,7 @@
 import subprocess
 import tempfile
 
+from mercurial.pycompat import open
 from mercurial import (
     node,
     pycompat,
diff --git a/hgext/infinitepush/__init__.py b/hgext/infinitepush/__init__.py
--- a/hgext/infinitepush/__init__.py
+++ b/hgext/infinitepush/__init__.py
@@ -103,6 +103,8 @@
 
 from mercurial.i18n import _
 
+from mercurial.pycompat import open
+
 from mercurial.utils import (
     procutil,
     stringutil,
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -206,6 +206,7 @@
 import struct
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     bundle2,
     cmdutil,
diff --git a/hgext/fsmonitor/__init__.py b/hgext/fsmonitor/__init__.py
--- a/hgext/fsmonitor/__init__.py
+++ b/hgext/fsmonitor/__init__.py
@@ -117,7 +117,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import hex
-
+from mercurial.pycompat import open
 from mercurial import (
     context,
     encoding,
diff --git a/hgext/fastannotate/revmap.py b/hgext/fastannotate/revmap.py
--- a/hgext/fastannotate/revmap.py
+++ b/hgext/fastannotate/revmap.py
@@ -13,6 +13,7 @@
 import struct
 
 from mercurial.node import hex
+from mercurial.pycompat import open
 from mercurial import (
     error as hgerror,
     pycompat,
diff --git a/hgext/fastannotate/protocol.py b/hgext/fastannotate/protocol.py
--- a/hgext/fastannotate/protocol.py
+++ b/hgext/fastannotate/protocol.py
@@ -10,6 +10,7 @@
 import os
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     extensions,
diff --git a/hgext/fastannotate/context.py b/hgext/fastannotate/context.py
--- a/hgext/fastannotate/context.py
+++ b/hgext/fastannotate/context.py
@@ -13,6 +13,7 @@
 import os
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     linelog as linelogmod,
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -8,6 +8,7 @@
 import xml.dom.minidom
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
diff --git a/hgext/convert/monotone.py b/hgext/convert/monotone.py
--- a/hgext/convert/monotone.py
+++ b/hgext/convert/monotone.py
@@ -11,6 +11,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     error,
     pycompat,
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -23,6 +23,7 @@
 import time
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     bookmarks,
     context,
diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py
+++ b/hgext/convert/cvsps.py
@@ -11,6 +11,7 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
--- a/hgext/convert/cvs.py
+++ b/hgext/convert/cvs.py
@@ -12,6 +12,7 @@
 import socket
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -11,6 +11,7 @@
 import shutil
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -15,6 +15,7 @@
 import subprocess
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     encoding,
     error,
diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -15,6 +15,7 @@
 import time
 
 from mercurial.i18n import _
+from mercurial.pycompat import open
 from mercurial import (
     cmdutil,
     encoding,



To: indygreg, durin42, martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list