D2868: util: prefer "bytesio" to "stringio"
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Thu Mar 15 01:11:28 UTC 2018
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
The io.BytesIO and io.StringIO types enforce the type of
data being operated on. On Python 2, we use cStringIO.StringIO(),
which is lax about mixing types. On Python 3, we actually use
io.BytesIO. Ideally, we'd use io.BytesIO on Python 2. But I believe
its performance is poor compared to cString.StringIO().
Anyway, we canonically define our pycompat type as "stringio."
That name is misleading, especially on Python 3.
This commit renames the canonical symbols to "bytesio."
"stringio" is preserved as an alias for API compatibility. There
are a lot of callers in the repo and I hesitate to take away the
old name. I also don't feel like changing everything at this time.
But at least new callers can use a "proper" name.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D2868
AFFECTED FILES
mercurial/pure/mpatch.py
mercurial/pure/parsers.py
mercurial/pycompat.py
mercurial/util.py
CHANGE DETAILS
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -71,7 +71,9 @@
stderr = pycompat.stderr
stdin = pycompat.stdin
stdout = pycompat.stdout
-stringio = pycompat.stringio
+bytesio = pycompat.bytesio
+# TODO deprecate stringio name, as it is a lie on Python 3.
+stringio = bytesio
xmlrpclib = pycompat.xmlrpclib
httpserver = urllibcompat.httpserver
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -64,7 +64,9 @@
sysexecutable = sys.executable
if sysexecutable:
sysexecutable = os.fsencode(sysexecutable)
- stringio = io.BytesIO
+ bytesio = io.BytesIO
+ # TODO deprecate stringio name, as it is a lie on Python 3.
+ stringio = bytesio
def maplist(*args):
return list(map(*args))
@@ -343,7 +345,8 @@
getcwd = os.getcwd
sysexecutable = sys.executable
shlexsplit = shlex.split
- stringio = cStringIO.StringIO
+ bytesio = cStringIO.StringIO
+ stringio = bytesio
maplist = map
ziplist = zip
rawinput = raw_input
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -12,7 +12,7 @@
from ..node import nullid
from .. import pycompat
-stringio = pycompat.stringio
+stringio = pycompat.bytesio
_pack = struct.pack
diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py
+++ b/mercurial/pure/mpatch.py
@@ -10,7 +10,7 @@
import struct
from .. import pycompat
-stringio = pycompat.stringio
+stringio = pycompat.bytesio
class mpatchError(Exception):
"""error raised when a delta cannot be decoded
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list