Patchwork [3,of,4] extensions: copy extra __dict__ of original function

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


Yuya Nishihara - Feb. 28, 2016, 6:55 a.m.
# HG changeset patch
# User Yuya Nishihara <>
# Date 1452337443 -32400
#      Sat Jan 09 20:04:03 2016 +0900
# Node ID c8ea5f04dfb0c291ca29d89ab3bf93e75de60506
# Parent  a1c6174f988efe8b3dfa200fbbe6a5a7de51268a
extensions: copy extra __dict__ of original function

Future patches will make @command decorator set properties such as "norepo" to
a function object. This patch makes sure these properties never be lost by
wrapcommand() or wrapfunction().

This change won't be crazy as the standard functools.wraps() copies __dict__.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -199,6 +199,7 @@  def _updatewrapper(wrap, origfn):
     '''Copy attributes to wrapper function'''
     wrap.__module__ = getattr(origfn, '__module__')
     wrap.__doc__ = getattr(origfn, '__doc__')
+    wrap.__dict__.update(getattr(origfn, '__dict__', {}))
 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None):
     '''Wrap the command named `command' in table