Patchwork [2,of,2] templater: fix string representation of wrapped None

login
register
mail settings
Submitter Yuya Nishihara
Date June 8, 2018, 2:52 p.m.
Message ID <1b8ab2494e427973a34e.1528469550@mimosa>
Download mbox | patch
Permalink /patch/32036/
State Accepted
Headers show

Comments

Yuya Nishihara - June 8, 2018, 2:52 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1528202433 -32400
#      Tue Jun 05 21:40:33 2018 +0900
# Node ID 1b8ab2494e427973a34e9ab2fe4652a6ec73dbe7
# Parent  ac754116b7cdebdcf41b8de8a9e9b2b8e6006e4e
templater: fix string representation of wrapped None

flatten() and stringify() skip None, which means wrappedvalue(None).show()
must return '' instead of 'None'. This isn't a problem right now, but we'll
encounter it once we start using wrapped types extensively.
Augie Fackler - June 11, 2018, 7:39 p.m.
On Fri, Jun 08, 2018 at 11:52:30PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1528202433 -32400
> #      Tue Jun 05 21:40:33 2018 +0900
> # Node ID 1b8ab2494e427973a34e9ab2fe4652a6ec73dbe7
> # Parent  ac754116b7cdebdcf41b8de8a9e9b2b8e6006e4e
> templater: fix string representation of wrapped None

queued, thanks

Patch

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -155,6 +155,8 @@  class wrappedvalue(wrapped):
         raise error.ParseError(_('%r is not iterable') % self._value)
 
     def show(self, context, mapping):
+        if self._value is None:
+            return b''
         return pycompat.bytestr(self._value)
 
     def tovalue(self, context, mapping):