[PATCH 4 of 6 py3] ui: fix opts labeling on ui.warn et al for Python 3

Yuya Nishihara yuya at tcha.org
Sun Mar 5 01:29:22 EST 2017


On Sat, 4 Mar 2017 16:46:16 +0530, Pulkit Goyal wrote:
> > diff --git a/mercurial/ui.py b/mercurial/ui.py
> > --- a/mercurial/ui.py
> > +++ b/mercurial/ui.py
> > @@ -1212,14 +1212,14 @@ class ui(object):
> >          This adds an output label of "ui.status".
> >          '''
> >          if not self.quiet:
> > -            opts['label'] = opts.get('label', '') + ' ui.status'
> > +            opts[u'label'] = opts.get(u'label', '') + ' ui.status'
> >              self.write(*msg, **opts)
> >      def warn(self, *msg, **opts):
> >          '''write warning message to output (stderr)
> >
> >          This adds an output label of "ui.warning".
> >          '''
> > -        opts['label'] = opts.get('label', '') + ' ui.warning'
> > +        opts[u'label'] = opts.get(u'label', '') + ' ui.warning'
> >          self.write_err(*msg, **opts)
> >      def note(self, *msg, **opts):
> >          '''write note to output (if ui.verbose is True)
> > @@ -1227,7 +1227,7 @@ class ui(object):
> >          This adds an output label of "ui.note".
> >          '''
> >          if self.verbose:
> > -            opts['label'] = opts.get('label', '') + ' ui.note'
> > +            opts[u'label'] = opts.get(u'label', '') + ' ui.note'
> >              self.write(*msg, **opts)
> >      def debug(self, *msg, **opts):
> >          '''write debug message to output (if ui.debugflag is True)
> > @@ -1235,7 +1235,7 @@ class ui(object):
> >          This adds an output label of "ui.debug".
> >          '''
> >          if self.debugflag:
> > -            opts['label'] = opts.get('label', '') + ' ui.debug'
> > +            opts[u'label'] = opts.get(u'label', '') + ' ui.debug'
> >              self.write(*msg, **opts)
> >
> > ​Instead of adding u'' everywhere, it will be better to use
> pycompat.byteskwargs() and pycompat.strkwargs​() IMO.

Using u'' or r'' here seems better since this is one liner. I slightly prefer
r'' as it would introduce no difference on Python 2.


More information about the Mercurial-devel mailing list