D12252: py3: use io.BytesIO directly
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Wed Mar 2 00:44:12 UTC 2022
indygreg created this revision.
Herald added subscribers: mercurial-patches, Kwan.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Previously, pycompat.bytesio and pycompat.stringio referred to
io.BytesIO. And util.bytesio and util.stringio aliased the pycompat
symbols.
This commit switches everything to use io.BytesIO directly. util.bytesio
and util.stringio still exist to provide backwards compatibility, as
they were the preferred symbols.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D12252
AFFECTED FILES
hgext/phabricator.py
mercurial/pure/mpatch.py
mercurial/pure/parsers.py
mercurial/pycompat.py
mercurial/util.py
tests/test-basic.t
tests/test-util.py
CHANGE DETAILS
diff --git a/tests/test-util.py b/tests/test-util.py
--- a/tests/test-util.py
+++ b/tests/test-util.py
@@ -2,6 +2,7 @@
from __future__ import absolute_import
import contextlib
+import io
import itertools
import unittest
@@ -55,7 +56,7 @@
@contextlib.contextmanager
def capturestderr():
- """Replace utils.procutil.stderr with a pycompat.bytesio instance
+ """Replace utils.procutil.stderr with an io.BytesIO instance
The instance is made available as the return value of __enter__.
@@ -63,7 +64,7 @@
"""
orig = utils.procutil.stderr
- utils.procutil.stderr = pycompat.bytesio()
+ utils.procutil.stderr = io.BytesIO()
try:
yield utils.procutil.stderr
finally:
diff --git a/tests/test-basic.t b/tests/test-basic.t
--- a/tests/test-basic.t
+++ b/tests/test-basic.t
@@ -240,15 +240,16 @@
Underlying message streams should be updated when ui.fout/ferr are set:
$ cat <<'EOF' > capui.py
- > from mercurial import pycompat, registrar
+ > import io
+ > from mercurial import registrar
> cmdtable = {}
> command = registrar.command(cmdtable)
> @command(b'capui', norepo=True)
> def capui(ui):
> out = ui.fout
- > ui.fout = pycompat.bytesio()
+ > ui.fout = io.BytesIO()
> ui.status(b'status\n')
- > ui.ferr = pycompat.bytesio()
+ > ui.ferr = io.BytesIO()
> ui.warn(b'warn\n')
> out.write(b'stdout: %s' % ui.fout.getvalue())
> out.write(b'stderr: %s' % ui.ferr.getvalue())
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -21,6 +21,7 @@
import errno
import gc
import hashlib
+import io
import itertools
import locale
import mmap
@@ -79,7 +80,7 @@
httplib = pycompat.httplib
safehasattr = pycompat.safehasattr
socketserver = pycompat.socketserver
-bytesio = pycompat.bytesio
+bytesio = io.BytesIO
# TODO deprecate stringio name, as it is a lie on Python 3.
stringio = bytesio
xmlrpclib = pycompat.xmlrpclib
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -110,9 +110,6 @@
sysexecutable = sys.executable
if sysexecutable:
sysexecutable = os.fsencode(sysexecutable)
-bytesio = io.BytesIO
-# TODO deprecate stringio name, as it is a lie on Python 3.
-stringio = bytesio
def maplist(*args):
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -7,6 +7,7 @@
from __future__ import absolute_import
+import io
import stat
import struct
import zlib
@@ -26,7 +27,7 @@
from ..revlogutils import nodemap as nodemaputil
from ..revlogutils import constants as revlog_constants
-stringio = pycompat.bytesio
+stringio = io.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
@@ -7,11 +7,11 @@
from __future__ import absolute_import
+import io
import struct
-from .. import pycompat
-stringio = pycompat.bytesio
+stringio = io.BytesIO
class mpatchError(Exception):
diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -62,6 +62,7 @@
import base64
import contextlib
import hashlib
+import io
import itertools
import json
import mimetypes
@@ -2200,7 +2201,7 @@
for drev, contents in patches:
ui.status(_(b'applying patch from D%s\n') % drev)
- with patch.extract(ui, pycompat.bytesio(contents)) as patchdata:
+ with patch.extract(ui, io.BytesIO(contents)) as patchdata:
msg, node, rej = cmdutil.tryimportone(
ui,
repo,
To: indygreg, #hg-reviewers
Cc: Kwan, mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list