uqfoundation/dill

Pickling lambda: "TypeError: cannot pickle '_struct.Struct' object"

Closed this issue · 0 comments

When I try to pickle a simple lambda:
dill.dumps(lambda x, y: Foo(args=(x, y.mutations)))
where

class Foo(NamedTuple):
    args: Sequence = ()
    kwargs: Mapping[str, Any] = {}

I get the following error:

  File "/usr/local/lib/python3.10/dist-packages/dill/_dill.py", line 422, in save
    StockPickler.save(self, obj, save_persistent_id)
  File "/usr/lib/python3.10/pickle.py", line 578, in save
    rv = reduce(self.proto)
TypeError: cannot pickle '_struct.Struct' object

cloudpickle has no such issue. I assume that this is a bug since I couldn't find any resources related to it on stackoverflow, the usecase seems quite generic and cloudpickle handles it correctly.