Read about our upcoming Code of Conduct on this issue

Commit bbaf916d authored by Gregory Szorc's avatar Gregory Szorc
Browse files

ui: avoid needless casting to a str

In many cases, we don't need to cast to a str because the object will
be cast when it is eventually written.

As part of testing this, I added some code to raise exceptions when a
non-str was passed in and wasn't able to trigger it. i.e. we're already
passing str into this function everywhere, so the casting isn't
parent a93d53f79e6e
......@@ -434,16 +434,15 @@ class colorui(uimod.ui):
label = opts.get('label', '')
if self._buffers:
if self._bufferapplylabels:
self._buffers[-1].extend(self.label(str(a), label)
for a in args)
self._buffers[-1].extend(self.label(a, label) for a in args)
self._buffers[-1].extend(str(a) for a in args)
elif self._colormode == 'win32':
for a in args:
win32print(a, super(colorui, self).write, **opts)
return super(colorui, self).write(
*[self.label(str(a), label) for a in args], **opts)
*[self.label(a, label) for a in args], **opts)
def write_err(self, *args, **opts):
if self._colormode is None:
......@@ -457,7 +456,7 @@ class colorui(uimod.ui):
win32print(a, super(colorui, self).write_err, **opts)
return super(colorui, self).write_err(
*[self.label(str(a), label) for a in args], **opts)
*[self.label(a, label) for a in args], **opts)
def showlabel(self, msg, label):
if label and msg:
......@@ -622,11 +622,11 @@ class ui(object):
a label of "status.modified" for modified files.
if self._buffers:
self._buffers[-1].extend([str(a) for a in args])
self._buffers[-1].extend(a for a in args)
for a in args:
def write_err(self, *args, **opts):
......@@ -636,7 +636,7 @@ class ui(object):
if not getattr(self.fout, 'closed', False):
for a in args:
# stderr may be buffered under win32 when redirected to files,
# including stdout.
if not getattr(self.ferr, 'closed', False):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment