changeset 29669:bdc81970853d

templatekw: change joinfmt to a mandatory argument of _hybrid object We've fixed several bugs caused by the misuse of the default joinfmt. Make it more explicit to prevent future bugs. dict.values()[0] is replaced by dict[element] as showlist() knows what the key is.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 23 Jul 2016 13:08:43 +0900
parents b76ea1384bf2
children 90d87ecbdcd8
files mercurial/templatekw.py
diffstat 1 files changed, 3 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Mon Jul 18 23:12:09 2016 +0900
+++ b/mercurial/templatekw.py	Sat Jul 23 13:08:43 2016 +0900
@@ -26,14 +26,11 @@
 #  "{get(extras, key)}"
 
 class _hybrid(object):
-    def __init__(self, gen, values, makemap, joinfmt=None):
+    def __init__(self, gen, values, makemap, joinfmt):
         self.gen = gen
         self.values = values
         self._makemap = makemap
-        if joinfmt:
-            self.joinfmt = joinfmt
-        else:
-            self.joinfmt = lambda x: x.values()[0]
+        self.joinfmt = joinfmt
     def __iter__(self):
         return self.gen
     def itermaps(self):
@@ -53,7 +50,7 @@
     if not element:
         element = name
     f = _showlist(name, values, plural, separator, **args)
-    return _hybrid(f, values, lambda x: {element: x})
+    return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element])
 
 def _showlist(name, values, plural=None, separator=' ', **args):
     '''expand set of values.