extensions: extract function that copies function attributes to wrapper
authorYuya Nishihara <yuya@tcha.org>
Sat, 09 Jan 2016 19:45:10 +0900
changeset 28310 01dc11e7191f
parent 28309 7c22b5bb3a03
child 28311 1b0ef07ba783
extensions: extract function that copies function attributes to wrapper wrapfunction() will be changed to copy these attributes. See the next patch for details.
mercurial/extensions.py
--- a/mercurial/extensions.py	Mon Feb 29 23:28:32 2016 +0000
+++ b/mercurial/extensions.py	Sat Jan 09 19:45:10 2016 +0900
@@ -195,6 +195,11 @@
         return func(*(args + a), **kw)
     return closure
 
+def _updatewrapper(wrap, origfn):
+    '''Copy attributes to wrapper function'''
+    wrap.__module__ = getattr(origfn, '__module__')
+    wrap.__doc__ = getattr(origfn, '__doc__')
+
 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None):
     '''Wrap the command named `command' in table
 
@@ -233,13 +238,9 @@
 
     origfn = entry[0]
     wrap = bind(util.checksignature(wrapper), util.checksignature(origfn))
-
-    wrap.__module__ = getattr(origfn, '__module__')
-
-    doc = getattr(origfn, '__doc__')
+    _updatewrapper(wrap, origfn)
     if docstring is not None:
-        doc += docstring
-    wrap.__doc__ = doc
+        wrap.__doc__ += docstring
 
     newentry = list(entry)
     newentry[0] = wrap