[PATCH 03 of 11 py3] basestring: introduce an alias for this type in pycompat
Augie Fackler
raf at durin42.com
Sun Oct 9 14:16:45 UTC 2016
# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1476020808 14400
# Sun Oct 09 09:46:48 2016 -0400
# Node ID b5f982c40f6721ab2db8ddcfe1b4f8df44ab25a2
# Parent 826ebebef37bd58fea9abdd4690ea7b5ad6b7552
basestring: introduce an alias for this type in pycompat
It's a mostly nonsense notion on py3, but it's still helpful for cases
where we care about "stringlike vs listlike" or similar.
diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -449,7 +449,7 @@ class converter(object):
commit = self.commitcache[rev]
full = self.opts.get('full')
changes = self.source.getchanges(rev, full)
- if isinstance(changes, basestring):
+ if isinstance(changes, pycompat.basestring):
if changes == SKIPREV:
dest = SKIPREV
else:
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3182,7 +3182,7 @@ def revert(ui, repo, ctx, parents, *pats
else:
util.rename(target, bakname)
if ui.verbose or not exact:
- if not isinstance(msg, basestring):
+ if not isinstance(msg, pycompat.basestring):
msg = msg(abs)
ui.status(msg % rel)
elif exact:
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -263,7 +263,7 @@ def callcatch(ui, func):
ui.warn(_("(%s)\n") % inst.hint)
except error.ResponseError as inst:
ui.warn(_("abort: %s") % inst.args[0])
- if not isinstance(inst.args[1], basestring):
+ if not isinstance(inst.args[1], pycompat.basestring):
ui.warn(" %r\n" % (inst.args[1],))
elif not inst.args[1]:
ui.warn(_(" empty string\n"))
diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -104,13 +104,13 @@ class httppeer(wireproto.wirepeer):
postargsok = self.caps is not None and 'httppostargs' in self.caps
# TODO: support for httppostargs when data is a file-like
# object rather than a basestring
- canmungedata = not data or isinstance(data, basestring)
+ canmungedata = not data or isinstance(data, pycompat.basestring)
if postargsok and canmungedata:
strargs = urlreq.urlencode(sorted(args.items()))
if strargs:
if not data:
data = strargs
- elif isinstance(data, basestring):
+ elif isinstance(data, pycompat.basestring):
data = strargs + data
headers['X-HgArgs-Post'] = len(strargs)
else:
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -87,6 +87,11 @@ class _pycompatstub(object):
self.__dict__[name] = obj = getattr(origin, item)
return obj
+try:
+ basestring
+except NameError:
+ basestring = (bytes, str)
+
httpserver = _pycompatstub()
urlreq = _pycompatstub()
urlerr = _pycompatstub()
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -25,6 +25,7 @@ from . import (
error,
formatter,
progress,
+ pycompat,
scmutil,
util,
)
@@ -520,7 +521,7 @@ class ui(object):
result = self.config(section, name, untrusted=untrusted)
if result is None:
result = default or []
- if isinstance(result, basestring):
+ if isinstance(result, pycompat.basestring):
result = _configlist(result.lstrip(' ,\n'))
if result is None:
result = default or []
More information about the Mercurial-devel
mailing list