The wrapped function now uses the same name as the original.

This commit is contained in:
Pedro Algarvio 2013-07-28 23:16:06 +01:00
parent 4855c9427c
commit 1f83aa6743

View File

@ -137,11 +137,18 @@ def identical_signature_wrapper(original_function, wrapped_function):
Return a function with identical signature as ``original_function``'s which
will call the ``wrapped_function``.
'''
function_def = 'lambda {0}: __wrapped__({0})'.format(
inspect.formatargspec(
formatvalue=lambda val: '',
*inspect.getargspec(original_function)
)[1:-1]
context = {'__wrapped__': wrapped_function}
function_def = compile(
'def {0}({1}):\n'
' return __wrapped__({1})'.format(
original_function.__name__,
inspect.formatargspec(
formatvalue=lambda val: '',
*inspect.getargspec(original_function)
)[1:-1]
),
'<string>',
'exec'
)
fake_function = eval(function_def, {'__wrapped__': wrapped_function})
return wraps(original_function)(fake_function)
exec function_def in context
return wraps(original_function)(context[original_function.__name__])