mirror of
https://github.com/facebook/sapling.git
synced 2025-01-07 14:10:42 +03:00
extensions: fix wrapcommand/function of class instance
5f4c097a17d2 changed _updatewrapper() to copy the __name__ attribute, but not all callable objects has __name__. Spotted by loading mq with extdiff.
This commit is contained in:
parent
792f16d38c
commit
04508d7f1c
@ -333,7 +333,10 @@ def bind(func, *args):
|
||||
|
||||
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__', {}))
|
||||
|
@ -54,3 +54,11 @@ with wrap1:
|
||||
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())
|
||||
|
@ -18,3 +18,4 @@ context manager [0, 1, 'orig']
|
||||
context manager [2, 0, 1, 'orig']
|
||||
context manager [2, 1, 'orig']
|
||||
context manager [2, 'orig']
|
||||
wrap callable object [0, 'orig']
|
||||
|
Loading…
Reference in New Issue
Block a user