-
-
Notifications
You must be signed in to change notification settings - Fork 189
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels