Mercurial > public > mercurial-scm > hg
comparison mercurial/extensions.py @ 28312:24f1d3c70c41
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__.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 09 Jan 2016 20:04:03 +0900 |
parents | 1b0ef07ba783 |
children | d5512a0a8ad6 |
comparison
equal
deleted
inserted
replaced
28311:1b0ef07ba783 | 28312:24f1d3c70c41 |
---|---|
197 | 197 |
198 def _updatewrapper(wrap, origfn): | 198 def _updatewrapper(wrap, origfn): |
199 '''Copy attributes to wrapper function''' | 199 '''Copy attributes to wrapper function''' |
200 wrap.__module__ = getattr(origfn, '__module__') | 200 wrap.__module__ = getattr(origfn, '__module__') |
201 wrap.__doc__ = getattr(origfn, '__doc__') | 201 wrap.__doc__ = getattr(origfn, '__doc__') |
202 wrap.__dict__.update(getattr(origfn, '__dict__', {})) | |
202 | 203 |
203 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None): | 204 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None): |
204 '''Wrap the command named `command' in table | 205 '''Wrap the command named `command' in table |
205 | 206 |
206 Replace command in the command table with wrapper. The wrapped command will | 207 Replace command in the command table with wrapper. The wrapped command will |