Patchwork pycompat: move imports of cStringIO/io to where they are used

login
register
mail settings
Submitter Yuya Nishihara
Date March 12, 2017, 8:16 p.m.
Message ID <442615c97b9787fd864d.1489349803@mimosa>
Download mbox | patch
Permalink /patch/19237/
State Accepted
Headers show

Comments

Yuya Nishihara - March 12, 2017, 8:16 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1489348451 25200
#      Sun Mar 12 12:54:11 2017 -0700
# Node ID 442615c97b9787fd864d8a59b4076eca3a15a0b0
# Parent  8a17c541177f32348e248608b6a9dfd7fefdf517
pycompat: move imports of cStringIO/io to where they are used

There's no point to import cStringIO as io since we have to select StringIO
or BytesIO conditionally.
Augie Fackler - March 12, 2017, 9:56 p.m.
On Sun, Mar 12, 2017 at 01:16:43PM -0700, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1489348451 25200
> #      Sun Mar 12 12:54:11 2017 -0700
> # Node ID 442615c97b9787fd864d8a59b4076eca3a15a0b0
> # Parent  8a17c541177f32348e248608b6a9dfd7fefdf517
> pycompat: move imports of cStringIO/io to where they are used

queued, thanks

>
> There's no point to import cStringIO as io since we have to select StringIO
> or BytesIO conditionally.
>
> diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
> --- a/mercurial/pycompat.py
> +++ b/mercurial/pycompat.py
> @@ -19,7 +19,6 @@ ispy3 = (sys.version_info[0] >= 3)
>
>  if not ispy3:
>      import cPickle as pickle
> -    import cStringIO as io
>      import httplib
>      import Queue as _queue
>      import SocketServer as socketserver
> @@ -28,7 +27,6 @@ if not ispy3:
>      import xmlrpclib
>  else:
>      import http.client as httplib
> -    import io
>      import pickle
>      import queue as _queue
>      import socketserver
> @@ -39,6 +37,8 @@ else:
>  if ispy3:
>      import builtins
>      import functools
> +    import io
> +
>      fsencode = os.fsencode
>      fsdecode = os.fsdecode
>      # A bytes version of os.name.
> @@ -139,6 +139,8 @@ if ispy3:
>          return [a.encode('latin-1') for a in ret]
>
>  else:
> +    import cStringIO
> +
>      bytechr = chr
>
>      def sysstr(s):
> @@ -181,7 +183,7 @@ else:
>      getcwd = os.getcwd
>      sysexecutable = sys.executable
>      shlexsplit = shlex.split
> -    stringio = io.StringIO
> +    stringio = cStringIO.StringIO
>
>  empty = _queue.Empty
>  queue = _queue.Queue
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -19,7 +19,6 @@  ispy3 = (sys.version_info[0] >= 3)
 
 if not ispy3:
     import cPickle as pickle
-    import cStringIO as io
     import httplib
     import Queue as _queue
     import SocketServer as socketserver
@@ -28,7 +27,6 @@  if not ispy3:
     import xmlrpclib
 else:
     import http.client as httplib
-    import io
     import pickle
     import queue as _queue
     import socketserver
@@ -39,6 +37,8 @@  else:
 if ispy3:
     import builtins
     import functools
+    import io
+
     fsencode = os.fsencode
     fsdecode = os.fsdecode
     # A bytes version of os.name.
@@ -139,6 +139,8 @@  if ispy3:
         return [a.encode('latin-1') for a in ret]
 
 else:
+    import cStringIO
+
     bytechr = chr
 
     def sysstr(s):
@@ -181,7 +183,7 @@  else:
     getcwd = os.getcwd
     sysexecutable = sys.executable
     shlexsplit = shlex.split
-    stringio = io.StringIO
+    stringio = cStringIO.StringIO
 
 empty = _queue.Empty
 queue = _queue.Queue