changeset 43090:1f339b503a40

py3: manually import pycompat.delattr where it is needed And with this change, we no longer need the auto-inserted import statement in the source transformer, so it has been removed! Differential Revision: https://phab.mercurial-scm.org/D7010
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Oct 2019 16:58:55 -0400
parents c59eb1560c44
children 127cc1f72e70
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
diffstat 9 files changed, 12 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/hgext/mq.py	Sun Oct 06 16:58:55 2019 -0400
@@ -77,6 +77,7 @@
     short,
 )
 from mercurial.pycompat import (
+    delattr,
     getattr,
     open,
 )
--- a/mercurial/__init__.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/__init__.py	Sun Oct 06 16:58:55 2019 -0400
@@ -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.
--- a/mercurial/dirstate.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/dirstate.py	Sun Oct 06 16:58:55 2019 -0400
@@ -15,6 +15,7 @@
 
 from .i18n import _
 from .node import nullid
+from .pycompat import delattr
 from . import (
     encoding,
     error,
--- a/mercurial/localrepo.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/localrepo.py	Sun Oct 06 16:58:55 2019 -0400
@@ -23,7 +23,10 @@
     nullrev,
     short,
 )
-from .pycompat import getattr
+from .pycompat import (
+    delattr,
+    getattr,
+)
 from . import (
     bookmarks,
     branchmap,
--- a/mercurial/merge.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/merge.py	Sun Oct 06 16:58:55 2019 -0400
@@ -23,6 +23,7 @@
     nullid,
     nullrev,
 )
+from .pycompat import delattr
 from .thirdparty import attr
 from . import (
     copies,
--- a/mercurial/pycompat.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/pycompat.py	Sun Oct 06 16:58:55 2019 -0400
@@ -355,6 +355,7 @@
     strurl = identity
     bytesurl = identity
     open = open
+    delattr = delattr
     getattr = getattr
     hasattr = hasattr
     setattr = setattr
--- a/mercurial/repoview.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/repoview.py	Sun Oct 06 16:58:55 2019 -0400
@@ -13,6 +13,7 @@
 
 from .node import nullrev
 from .pycompat import (
+    delattr,
     getattr,
     setattr,
 )
--- a/mercurial/util.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/util.py	Sun Oct 06 16:58:55 2019 -0400
@@ -36,6 +36,7 @@
 
 from .thirdparty import attr
 from .pycompat import (
+    delattr,
     getattr,
     open,
     setattr,
--- a/mercurial/vfs.py	Sun Oct 06 16:55:18 2019 -0400
+++ b/mercurial/vfs.py	Sun Oct 06 16:58:55 2019 -0400
@@ -15,6 +15,7 @@
 
 from .i18n import _
 from .pycompat import (
+    delattr,
     getattr,
     setattr,
 )