extensions: set attributes to wrappers so we can trace them back
This patch adds two attributes about the original function and the unbound
wrapper. It allows us to get a chain of wrappers. See the next patch.
--- a/mercurial/extensions.py Wed Aug 10 15:05:20 2016 +0100
+++ b/mercurial/extensions.py Wed Aug 10 15:21:42 2016 +0100
@@ -210,11 +210,13 @@
return func(*(args + a), **kw)
return closure
-def _updatewrapper(wrap, origfn):
- '''Copy attributes to wrapper function'''
+def _updatewrapper(wrap, origfn, unboundwrapper):
+ '''Copy and add some useful attributes to wrapper'''
wrap.__module__ = getattr(origfn, '__module__')
wrap.__doc__ = getattr(origfn, '__doc__')
wrap.__dict__.update(getattr(origfn, '__dict__', {}))
+ wrap._origfunc = origfn
+ wrap._unboundwrapper = unboundwrapper
def wrapcommand(table, command, wrapper, synopsis=None, docstring=None):
'''Wrap the command named `command' in table
@@ -254,7 +256,7 @@
origfn = entry[0]
wrap = bind(util.checksignature(wrapper), util.checksignature(origfn))
- _updatewrapper(wrap, origfn)
+ _updatewrapper(wrap, origfn, wrapper)
if docstring is not None:
wrap.__doc__ += docstring
@@ -303,7 +305,7 @@
origfn = getattr(container, funcname)
assert callable(origfn)
wrap = bind(wrapper, origfn)
- _updatewrapper(wrap, origfn)
+ _updatewrapper(wrap, origfn, wrapper)
setattr(container, funcname, wrap)
return origfn