Patchwork [2,of,5] templater: drop unneeded destructuring of argument tuple at buildfilter

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 1, 2015, 1:25 p.m.
Message ID <d8a5d9f3ff0f47cb46ae.1441113912@mimosa>
Download mbox | patch
Permalink /patch/10342/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 1, 2015, 1:25 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1441101850 -32400
#      Tue Sep 01 19:04:10 2015 +0900
# Node ID d8a5d9f3ff0f47cb46aef617a23cef29c7701f2d
# Parent  ca87b46db7986b048404fbff2ea25067d2db2233
templater: drop unneeded destructuring of argument tuple at buildfilter

Because evalfuncarg() accepts an argument tuple, there is little meaning
to pass (func, data, filt) in place of ((func, data), filt).

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -256,26 +256,26 @@  def runtemplate(context, mapping, templa
         yield func(context, mapping, data)
 
 def buildfilter(exp, context):
-    func, data = compileexp(exp[1], context, methods)
+    arg = compileexp(exp[1], context, methods)
     n = getsymbol(exp[2])
     if n in context._filters:
         filt = context._filters[n]
-        return (runfilter, (func, data, filt))
+        return (runfilter, (arg, filt))
     if n in funcs:
         f = funcs[n]
-        return (f, [(func, data)])
+        return (f, [arg])
     raise error.ParseError(_("unknown function '%s'") % n)
 
 def runfilter(context, mapping, data):
-    func, data, filt = data
-    thing = evalfuncarg(context, mapping, (func, data))
+    arg, filt = data
+    thing = evalfuncarg(context, mapping, arg)
     try:
         return filt(thing)
     except (ValueError, AttributeError, TypeError):
-        if isinstance(data, tuple):
-            dt = data[1]
+        if isinstance(arg[1], tuple):
+            dt = arg[1][1]
         else:
-            dt = data
+            dt = arg[1]
         raise util.Abort(_("template filter '%s' is not compatible with "
                            "keyword '%s'") % (filt.func_name, dt))
 
@@ -313,7 +313,7 @@  def buildfunc(exp, context):
         if len(args) != 1:
             raise error.ParseError(_("filter %s expects one argument") % n)
         f = context._filters[n]
-        return (runfilter, (args[0][0], args[0][1], f))
+        return (runfilter, (args[0], f))
     raise error.ParseError(_("unknown function '%s'") % n)
 
 def date(context, mapping, args):