Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dill.source.getsource returns decorated function instead of function #633

Open
thekevinscott opened this issue Dec 7, 2023 · 0 comments

Comments

@thekevinscott
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant