[PATCH 3 of 3] util: make util.py more demandimport friendly
Yuya Nishihara
yuya at tcha.org
Thu Jul 14 10:52:17 EDT 2016
On Thu, 14 Jul 2016 14:35:09 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1468438157 -19800
> # Thu Jul 14 00:59:17 2016 +0530
> # Node ID 98d10404151317b62c84832111f851e89c29214f
> # Parent 9f7d3de1e00bb71977e58990d637ceb590993fee
> util: make util.py more demandimport friendly
>
> There are modules which are renamed it Python 3, we used to add a hack in pycompat.py
> and then import it in util, now we have a if-else which checks the python version and imports
> the required module.
>
> diff -r 9f7d3de1e00b -r 98d104041513 mercurial/util.py
> --- a/mercurial/util.py Wed Jul 13 23:38:29 2016 +0530
> +++ b/mercurial/util.py Thu Jul 14 00:59:17 2016 +0530
> @@ -45,19 +45,37 @@
> pycompat,
> )
>
> +if sys.version_info[0] < 3:
> + import cPickle as pickle
> + import cStringIO as io
> + import httplib
> + import Queue as _queue
> + import SocketServer as socketserver
> + import urlparse
> + import xmlrpclib
> +else:
> + import http.client as httplib
> + import io
> + import pickle
> + import queue as _queue
> + import socketserver
> + import urllib.parse as urlparse
> + import xmlrpc.client as xmlrpclib
Perhaps we want this in pycompat.py.
> +empty = _queue.Empty
> +queue = _queue.Queue
> +stringio = io.StringIO
> +pickle.dumps
> +httplib.HTTPException
> +socketserver.ThreadingMixIn
> +xmlrpclib.Transport
> +urlparse.urlparse
And these lines are the reason why pycompat.py is demandimport unfriendly.
They do import modules.
More information about the Mercurial-devel
mailing list