[PATCH 2 of 2] templater: fix string representation of wrapped None

Yuya Nishihara yuya at tcha.org
Fri Jun 8 10:52:30 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at 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.

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):


More information about the Mercurial-devel mailing list