Patchwork [3,of,3] templatekw: deprecate old-style template keyword function (API)

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 6, 2018, 1:53 p.m.
Message ID <c31ae8d0e6c30b7acc2a.1533563630@mimosa>
Download mbox | patch
Permalink /patch/33334/
State New
Headers show

Comments

Yuya Nishihara - Aug. 6, 2018, 1:53 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519560273 -32400
#      Sun Feb 25 21:04:33 2018 +0900
# Node ID c31ae8d0e6c30b7acc2abfe1299c1122b05429e6
# Parent  7633562bfbe0ca069194cd0f86043cf31a6d78e0
templatekw: deprecate old-style template keyword function (API)

.. api::

   `f(**kwargs)` style template keyword function is deprecated. Switch to
   new `(context, mapping)` API by declaring resource requirements.
   The new-style API will be the default in Mercurial 4.9. See
   registrar.templatekeyword for details.

Patch

diff --git a/mercurial/registrar.py b/mercurial/registrar.py
--- a/mercurial/registrar.py
+++ b/mercurial/registrar.py
@@ -295,7 +295,7 @@  class templatekeyword(_templateregistrar
             '''
             pass
 
-        # old API
+        # old API (DEPRECATED)
         @templatekeyword('mykeyword')
         def mykeywordfunc(repo, ctx, templ, cache, revcache, **args):
             '''Explanation of this template keyword ....
diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -810,8 +810,9 @@  def runstring(context, mapping, data):
     return data
 
 def _recursivesymbolblocker(key):
-    def showrecursion(**args):
+    def showrecursion(context, mapping):
         raise error.Abort(_("recursive reference '%s' in template") % key)
+    showrecursion._requires = ()  # mark as new-style templatekw
     return showrecursion
 
 def runsymbol(context, mapping, key, default=''):
@@ -827,12 +828,16 @@  def runsymbol(context, mapping, key, def
             v = default
     if callable(v) and getattr(v, '_requires', None) is None:
         # old templatekw: expand all keywords and resources
-        # (TODO: deprecate this after porting web template keywords to new API)
+        # (TODO: drop support for old-style functions. 'f._requires = ()'
+        #  can be removed.)
         props = {k: context._resources.lookup(context, mapping, k)
                  for k in context._resources.knownkeys()}
         # pass context to _showcompatlist() through templatekw._showlist()
         props['templ'] = context
         props.update(mapping)
+        ui = props.get('ui')
+        if ui:
+            ui.deprecwarn("old-style template keyword '%s'" % key, '4.8')
         return v(**pycompat.strkwargs(props))
     if callable(v):
         # new templatekw