# HG changeset patch # User Yuya Nishihara # Date 1505054234 -32400 # Node ID 82bd4c5a81e585111d5edd8a42b637992924dda5 # Parent 709b44f38ab919c4f858f12807b9f01f6a2ee888 extensions: fix wrapcommand/function of class instance 5361771f9714 changed _updatewrapper() to copy the __name__ attribute, but not all callable objects has __name__. Spotted by loading mq with extdiff. diff -r 709b44f38ab9 -r 82bd4c5a81e5 mercurial/extensions.py --- a/mercurial/extensions.py Tue Sep 12 09:13:02 2017 -0700 +++ b/mercurial/extensions.py Sun Sep 10 23:37:14 2017 +0900 @@ -333,7 +333,10 @@ def _updatewrapper(wrap, origfn, unboundwrapper): '''Copy and add some useful attributes to wrapper''' - wrap.__name__ = origfn.__name__ + try: + wrap.__name__ = origfn.__name__ + except AttributeError: + pass wrap.__module__ = getattr(origfn, '__module__') wrap.__doc__ = getattr(origfn, '__doc__') wrap.__dict__.update(getattr(origfn, '__dict__', {})) diff -r 709b44f38ab9 -r 82bd4c5a81e5 tests/test-extensions-wrapfunction.py --- a/tests/test-extensions-wrapfunction.py Tue Sep 12 09:13:02 2017 -0700 +++ b/tests/test-extensions-wrapfunction.py Sun Sep 10 23:37:14 2017 +0900 @@ -54,3 +54,11 @@ print('context manager', dummy.getstack()) print('context manager', dummy.getstack()) print('context manager', dummy.getstack()) + +# Wrap callable object which has no __name__ +class callableobj(object): + def __call__(self): + return ['orig'] +dummy.cobj = callableobj() +extensions.wrapfunction(dummy, 'cobj', wrappers[0]) +print('wrap callable object', dummy.cobj()) diff -r 709b44f38ab9 -r 82bd4c5a81e5 tests/test-extensions-wrapfunction.py.out --- a/tests/test-extensions-wrapfunction.py.out Tue Sep 12 09:13:02 2017 -0700 +++ b/tests/test-extensions-wrapfunction.py.out Sun Sep 10 23:37:14 2017 +0900 @@ -18,3 +18,4 @@ context manager [2, 0, 1, 'orig'] context manager [2, 1, 'orig'] context manager [2, 'orig'] +wrap callable object [0, 'orig']