Patchwork [2,of,4] templater: make get(dict, key) return a single value

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 16, 2016, 12:47 p.m.
Message ID <45706351a9bbc0060956.1452948471@mimosa>
Download mbox | patch
Permalink /patch/12795/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 16, 2016, 12:47 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1452920012 -32400
#      Sat Jan 16 13:53:32 2016 +0900
# Node ID 45706351a9bbc0060956521951ab319ffbd22b76
# Parent  34bd032d95483c8bbdcd6269d0cc04f921e3abdc
templater: make get(dict, key) return a single value

This is necessary to obtain a _hybrid object from a dict. If get() yields
a value, it would be stringified.

I see no benefit to make get() lazy, so this patch just changes "yield" to
"return".

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -432,7 +432,7 @@  def get(context, mapping, args):
         raise error.ParseError(_("get() expects a dict as first argument"))
 
     key = args[1][0](context, mapping, args[1][1])
-    yield dictarg.get(key)
+    return dictarg.get(key)
 
 def if_(context, mapping, args):
     """:if(expr, then[, else]): Conditionally execute based on the result of