changeset 48961:df56e6bd37f6

py3: use pickle directly 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. Differential Revision: https://phab.mercurial-scm.org/D12249
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 01 Mar 2022 20:29:03 -0800
parents 57b58413dad1
children 79009cca491e
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
diffstat 10 files changed, 11 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/contrib/check-code.py	Tue Mar 01 20:29:03 2022 -0800
@@ -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"),
         (
--- a/hgext/convert/common.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/hgext/convert/common.py	Tue Mar 01 20:29:03 2022 -0800
@@ -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
 
 
--- a/hgext/convert/cvsps.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/hgext/convert/cvsps.py	Tue Mar 01 20:29:03 2022 -0800
@@ -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:
--- a/hgext/convert/subversion.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/hgext/convert/subversion.py	Tue Mar 01 20:29:03 2022 -0800
@@ -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
--- a/hgext/histedit.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/hgext/histedit.py	Tue Mar 01 20:29:03 2022 -0800
@@ -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)
 
--- a/mercurial/formatter.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/mercurial/formatter.py	Tue Mar 01 20:29:03 2022 -0800
@@ -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
--- a/mercurial/util.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/mercurial/util.py	Tue Mar 01 20:29:03 2022 -0800
@@ -76,7 +76,6 @@
 
 cookielib = pycompat.cookielib
 httplib = pycompat.httplib
-pickle = pycompat.pickle
 safehasattr = pycompat.safehasattr
 socketserver = pycompat.socketserver
 bytesio = pycompat.bytesio
--- a/mercurial/worker.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/mercurial/worker.py	Tue Mar 01 20:29:03 2022 -0800
@@ -9,6 +9,7 @@
 
 import errno
 import os
+import pickle
 import signal
 import sys
 import threading
@@ -27,7 +28,6 @@
     error,
     pycompat,
     scmutil,
-    util,
 )
 
 
@@ -256,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)
@@ -292,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:
--- a/tests/test-status.t	Wed Mar 02 17:51:27 2022 -0800
+++ b/tests/test-status.t	Tue Mar 01 20:29:03 2022 -0800
@@ -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
--- a/tests/test-stdio.py	Wed Mar 02 17:51:27 2022 -0800
+++ b/tests/test-stdio.py	Tue Mar 01 20:29:03 2022 -0800
@@ -7,6 +7,7 @@
 import contextlib
 import errno
 import os
+import pickle
 import signal
 import subprocess
 import sys
@@ -336,7 +337,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")