# HG changeset patch # User Gregory Szorc # Date 1645394606 25200 # Node ID 5aafc3c5bdeca9b832a72f91871bf4260785fab7 # Parent 968b29a5a7fc9e383770ea19ce27aada81ec58b0 py3: use io.BytesIO directly 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. Differential Revision: https://phab.mercurial-scm.org/D12252 diff -r 968b29a5a7fc -r 5aafc3c5bdec hgext/phabricator.py --- a/hgext/phabricator.py Sun Feb 20 14:52:40 2022 -0700 +++ b/hgext/phabricator.py Sun Feb 20 15:03:26 2022 -0700 @@ -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, diff -r 968b29a5a7fc -r 5aafc3c5bdec mercurial/pure/mpatch.py --- a/mercurial/pure/mpatch.py Sun Feb 20 14:52:40 2022 -0700 +++ b/mercurial/pure/mpatch.py Sun Feb 20 15:03:26 2022 -0700 @@ -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 -r 968b29a5a7fc -r 5aafc3c5bdec mercurial/pure/parsers.py --- a/mercurial/pure/parsers.py Sun Feb 20 14:52:40 2022 -0700 +++ b/mercurial/pure/parsers.py Sun Feb 20 15:03:26 2022 -0700 @@ -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 -r 968b29a5a7fc -r 5aafc3c5bdec mercurial/pycompat.py --- a/mercurial/pycompat.py Sun Feb 20 14:52:40 2022 -0700 +++ b/mercurial/pycompat.py Sun Feb 20 15:03:26 2022 -0700 @@ -111,9 +111,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 -r 968b29a5a7fc -r 5aafc3c5bdec mercurial/util.py --- a/mercurial/util.py Sun Feb 20 14:52:40 2022 -0700 +++ b/mercurial/util.py Sun Feb 20 15:03:26 2022 -0700 @@ -21,6 +21,7 @@ import errno import gc import hashlib +import io import itertools import locale import mmap @@ -78,7 +79,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 -r 968b29a5a7fc -r 5aafc3c5bdec tests/test-basic.t --- a/tests/test-basic.t Sun Feb 20 14:52:40 2022 -0700 +++ b/tests/test-basic.t Sun Feb 20 15:03:26 2022 -0700 @@ -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 -r 968b29a5a7fc -r 5aafc3c5bdec tests/test-util.py --- a/tests/test-util.py Sun Feb 20 14:52:40 2022 -0700 +++ b/tests/test-util.py Sun Feb 20 15:03:26 2022 -0700 @@ -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: