changeset 28310:01dc11e7191f

extensions: extract function that copies function attributes to wrapper wrapfunction() will be changed to copy these attributes. See the next patch for details.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 09 Jan 2016 19:45:10 +0900
parents 7c22b5bb3a03
children 1b0ef07ba783
files mercurial/extensions.py
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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