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

Metadata of wrapper functions not preserved #602

Open
dfremont opened this issue Jul 2, 2023 · 1 comment
Open

Metadata of wrapper functions not preserved #602

dfremont opened this issue Jul 2, 2023 · 1 comment

Comments

@dfremont
Copy link

dfremont commented Jul 2, 2023

dill seems to not preserve the metadata of functions wrapped with functools.wraps. With dill 0.3.6 on Python 3.11.1, the following code:

import functools

import dill

def a(x):
    return 42

@functools.wraps(a)
def b(x):
    return a(x)

data = dill.dumps(b)
c = dill.loads(data)

print(f'{a=}, {b=}, {c=}')

prints something along the lines of

a=<function a at 0x108164a40>, b=<function a at 0x1081963e0>, c=<function b at 0x108ca2fc0>

where the unpickled function should have name a like the original does.

I thought the issue might be that the __qualname__ attribute of the function wasn't getting saved, but setting that attribute manually rather than using functools.wraps actually works; the code

def d(x):
    return 42

d.__qualname__ = 'foo'

data = dill.dumps(d)
e = dill.loads(data)

print(f'{d=}, {e=}')

prints something like

d=<function foo at 0x10bd58860>, e=<function foo at 0x10c892fc0>

where now the name of the unpickled function is correct. So I don't know what's going on.

@dfremont
Copy link
Author

Hi @mmckerns, I'm still seeing this issue with dill 0.3.7 -- any idea what the cause might be? I haven't been able to figure out why the second snippet above works while the first one doesn't.

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