D7010: py3: manually import pycompat.delattr where it is needed

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Mon Oct 7 10:41:31 EDT 2019


Closed by commit rHG1f339b503a40: py3: manually import pycompat.delattr where it is needed (authored by indygreg).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7010?vs=16925&id=16933

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7010/new/

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

AFFECTED FILES
  hgext/mq.py
  mercurial/__init__.py
  mercurial/dirstate.py
  mercurial/localrepo.py
  mercurial/merge.py
  mercurial/pycompat.py
  mercurial/repoview.py
  mercurial/util.py
  mercurial/vfs.py

CHANGE DETAILS

diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -15,6 +15,7 @@
 
 from .i18n import _
 from .pycompat import (
+    delattr,
     getattr,
     setattr,
 )
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -36,6 +36,7 @@
 
 from .thirdparty import attr
 from .pycompat import (
+    delattr,
     getattr,
     open,
     setattr,
diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -13,6 +13,7 @@
 
 from .node import nullrev
 from .pycompat import (
+    delattr,
     getattr,
     setattr,
 )
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -355,6 +355,7 @@
     strurl = identity
     bytesurl = identity
     open = open
+    delattr = delattr
     getattr = getattr
     hasattr = hasattr
     setattr = setattr
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -23,6 +23,7 @@
     nullid,
     nullrev,
 )
+from .pycompat import delattr
 from .thirdparty import attr
 from . import (
     copies,
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -23,7 +23,10 @@
     nullrev,
     short,
 )
-from .pycompat import getattr
+from .pycompat import (
+    delattr,
+    getattr,
+)
 from . import (
     bookmarks,
     branchmap,
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -15,6 +15,7 @@
 
 from .i18n import _
 from .node import nullid
+from .pycompat import delattr
 from . import (
     encoding,
     error,
diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -101,8 +101,6 @@
         REMEMBER TO CHANGE ``BYTECODEHEADER`` WHEN CHANGING THIS FUNCTION
         OR CACHED FILES WON'T GET INVALIDATED PROPERLY.
         """
-        futureimpline = False
-
         # The following utility functions access the tokens list and i index of
         # the for i, t enumerate(tokens) loop below
         def _isop(j, *o):
@@ -153,34 +151,6 @@
                 tokens[j] = st._replace(string='u%s' % st.string)
 
         for i, t in enumerate(tokens):
-            # Insert compatibility imports at "from __future__ import" line.
-            # No '\n' should be added to preserve line numbers.
-            if (
-                t.type == token.NAME
-                and t.string == 'import'
-                and all(u.type == token.NAME for u in tokens[i - 2 : i])
-                and [u.string for u in tokens[i - 2 : i]]
-                == ['from', '__future__']
-            ):
-                futureimpline = True
-            if t.type == token.NEWLINE and futureimpline:
-                futureimpline = False
-                if fullname == 'mercurial.pycompat':
-                    yield t
-                    continue
-                r, c = t.start
-                l = (
-                    b'; from mercurial.pycompat import '
-                    b'delattr\n'
-                )
-                for u in tokenize.tokenize(io.BytesIO(l).readline):
-                    if u.type in (tokenize.ENCODING, token.ENDMARKER):
-                        continue
-                    yield u._replace(
-                        start=(r, c + u.start[1]), end=(r, c + u.end[1])
-                    )
-                continue
-
             # This looks like a function call.
             if t.type == token.NAME and _isop(i + 1, '('):
                 fn = t.string
@@ -220,7 +190,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\x11'
+    BYTECODEHEADER = b'HG\x00\x12'
 
     class hgloader(importlib.machinery.SourceFileLoader):
         """Custom module loader that transforms source code.
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -77,6 +77,7 @@
     short,
 )
 from mercurial.pycompat import (
+    delattr,
     getattr,
     open,
 )



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


More information about the Mercurial-devel mailing list