Patchwork [1,of,4] extensions: extract function that copies function attributes to wrapper

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 28, 2016, 6:55 a.m.
Message ID <f2cbcdf4d88896db8a36.1456642540@mimosa>
Download mbox | patch
Permalink /patch/13448/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 28, 2016, 6:55 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1452336310 -32400
#      Sat Jan 09 19:45:10 2016 +0900
# Node ID f2cbcdf4d88896db8a36282f3254173afe9e0059
# Parent  10eaae94523c790d7b77c52a4cb4bfcf406021ef
extensions: extract function that copies function attributes to wrapper

wrapfunction() will be changed to copy these attributes. See the next patch
for details.

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -195,6 +195,11 @@  def bind(func, *args):
         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 @@  def wrapcommand(table, command, wrapper,
 
     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