dill.source.getsource returns decorated function instead of function
thekevinscott opened this issue · comments
Kevin Scott commented
I see a few possibly related issues (#221, #603) but I think this is unique.
I'm running the following in pytest:
def test_fn():
def decorate(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return f"decorated: {result}"
return wrapper
@decorate
def foo(arg1: str = "arg1"):
return f"foo: {arg1}"
print(dedent(inspect.getsource(foo)))
print(dedent(dill.source.getsource(foo)))
The printed statements read:
@decorate
def foo(arg1: str = "arg1"):
return f"foo: {arg1}"
@functools.wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return f"decorated: {result}"
The inspect.getsource
statement returns the function foo
with the decorator decorating, but the dill.source.getsource
returns the wrapper
function from the decorator.
I would expect dill.source.getsource
to return what inspect.getsource
.
If I'm wildly misunderstanding the purpose of dill.source.getsource
, feel free to close!