diff hgext/color.py @ 27110:f04bd381e8c0

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 necessary.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 22 Nov 2015 14:44:55 -0800
parents a93d53f79e6e
children 290b41913d9f
line wrap: on
line diff
--- a/hgext/color.py	Tue Nov 24 11:23:10 2015 -0800
+++ b/hgext/color.py	Sun Nov 22 14:44:55 2015 -0800
@@ -434,16 +434,15 @@
         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)
             else:
-                self._buffers[-1].extend(str(a) for a in args)
+                self._buffers[-1].extend(args)
         elif self._colormode == 'win32':
             for a in args:
                 win32print(a, super(colorui, self).write, **opts)
         else:
             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 @@
                 win32print(a, super(colorui, self).write_err, **opts)
         else:
             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: