Patchwork D12249: py3: use pickle directly

login
register
mail settings
Submitter phabricator
Date March 2, 2022, 12:44 a.m.
Message ID <differential-rev-PHID-DREV-exzmaxp4zuaoibuac27j-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50594/
State New
Headers show

Comments

phabricator - March 2, 2022, 12:44 a.m.
indygreg created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  pycompat.pickle abstracted over the different pickle modules in
  Python 2 and 3. Now that we're Python 3 only, it is safe to use the
  `pickle` module directly. So this commit does that.
  
  As part of this we remove the rules from check-code.py that were
  forbidden direct pickle module use.
  
  We retain the `util.pickle` symbol for backwards compatibility, just
  in case some extensions were using it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  contrib/check-code.py
  hgext/convert/common.py
  hgext/convert/cvsps.py
  hgext/convert/subversion.py
  hgext/histedit.py
  mercurial/formatter.py
  mercurial/util.py
  mercurial/worker.py
  tests/test-status.t
  tests/test-stdio.py

CHANGE DETAILS




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

Patch

diff --git a/tests/test-stdio.py b/tests/test-stdio.py
--- a/tests/test-stdio.py
+++ b/tests/test-stdio.py
@@ -7,6 +7,7 @@ 
 import contextlib
 import errno
 import os
+import pickle
 import signal
 import subprocess
 import sys
@@ -335,7 +336,7 @@ 
             proc.stdin.close()
 
         def post_child_check():
-            err = util.pickle.load(err_f)
+            err = pickle.load(err_f)
             self.assertEqual(err.errno, errno.EPIPE)
             self.assertEqual(err.strerror, "Broken pipe")
 
diff --git a/tests/test-status.t b/tests/test-status.t
--- a/tests/test-status.t
+++ b/tests/test-status.t
@@ -316,8 +316,8 @@ 
 
   $ hg status -A -Tpickle > pickle
   >>> from __future__ import print_function
+  >>> import pickle
   >>> from mercurial import util
-  >>> pickle = util.pickle
   >>> data = sorted((x[b'status'].decode(), x[b'path'].decode()) for x in pickle.load(open("pickle", r"rb")))
   >>> for s, p in data: print("%s %s" % (s, p))
   ! deleted
diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -9,6 +9,7 @@ 
 
 import errno
 import os
+import pickle
 import signal
 import sys
 import threading
@@ -255,7 +256,7 @@ 
                         os.close(w)
                     os.close(rfd)
                     for result in func(*(staticargs + (pargs,))):
-                        os.write(wfd, util.pickle.dumps(result))
+                        os.write(wfd, pickle.dumps(result))
                     return 0
 
                 ret = scmutil.callcatch(ui, workerfunc)
@@ -291,7 +292,7 @@ 
         while openpipes > 0:
             for key, events in selector.select():
                 try:
-                    res = util.pickle.load(_blockingreader(key.fileobj))
+                    res = pickle.load(_blockingreader(key.fileobj))
                     if hasretval and res[0]:
                         retval.update(res[1])
                     else:
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -25,6 +25,7 @@ 
 import locale
 import mmap
 import os
+import pickle
 import platform as pyplatform
 import re as remod
 import shutil
@@ -76,7 +77,6 @@ 
 
 cookielib = pycompat.cookielib
 httplib = pycompat.httplib
-pickle = pycompat.pickle
 safehasattr = pycompat.safehasattr
 socketserver = pycompat.socketserver
 bytesio = pycompat.bytesio
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -110,6 +110,7 @@ 
 import contextlib
 import itertools
 import os
+import pickle
 
 from .i18n import _
 from .node import (
@@ -133,8 +134,6 @@ 
     stringutil,
 )
 
-pickle = util.pickle
-
 
 def isprintable(obj):
     """Check if the given object can be directly passed in to formatter's
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -202,6 +202,7 @@ 
 
 import functools
 import os
+import pickle
 import struct
 
 from mercurial.i18n import _
@@ -245,7 +246,6 @@ 
     urlutil,
 )
 
-pickle = util.pickle
 cmdtable = {}
 command = registrar.command(cmdtable)
 
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -6,6 +6,7 @@ 
 import codecs
 import locale
 import os
+import pickle
 import re
 import xml.dom.minidom
 
@@ -26,7 +27,6 @@ 
 
 from . import common
 
-pickle = util.pickle
 stringio = util.stringio
 propertycache = util.propertycache
 urlerr = util.urlerr
diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py
+++ b/hgext/convert/cvsps.py
@@ -8,6 +8,7 @@ 
 
 import functools
 import os
+import pickle
 import re
 
 from mercurial.i18n import _
@@ -25,8 +26,6 @@ 
     stringutil,
 )
 
-pickle = util.pickle
-
 
 class logentry(object):
     """Class logentry has the following attributes:
diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -10,6 +10,7 @@ 
 import datetime
 import errno
 import os
+import pickle
 import re
 import shlex
 import subprocess
@@ -25,7 +26,6 @@ 
 )
 from mercurial.utils import procutil
 
-pickle = util.pickle
 propertycache = util.propertycache
 
 
diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -446,8 +446,6 @@ 
         ),
         (r'^import urlparse', "don't use urlparse, use util.urlreq"),
         (r'^import xmlrpclib', "don't use xmlrpclib, use util.xmlrpclib"),
-        (r'^import cPickle', "don't use cPickle, use util.pickle"),
-        (r'^import pickle', "don't use pickle, use util.pickle"),
         (r'^import httplib', "don't use httplib, use util.httplib"),
         (r'^import BaseHTTPServer', "use util.httpserver instead"),
         (