intellimath / recordclass

Mutable variant of namedtuple -- recordclass, which support assignments, compact dataclasses and other memory saving variants.
Other
13 stars 4 forks source link

Dill doesn't think that dataclasses pickle #7

Open hulsed opened 1 month ago

hulsed commented 1 month ago

If I use the dill module to check whether dataclasses pickle, it throws some errors/warnings and returns false.

For example, in the following example:

from recordclass import dataobject
import dill

class Newdataclass(dataobject):
    a: float = 1.0

inputobj = Newdataclass()

does_it_pickle = dill.pickles(inputobj)

does_it_pickle returns False while the following warnings are thrown to the console:

image

intellimath commented 1 month ago

If class Newdataclass is defined in the module then does_it_pickle = dill.pickles(inputobj, byref=True) works for me.

intellimath commented 1 month ago

From docstring of dill.dumps:

''' If byref=True, then dill behaves a lot more like pickle as certain objects (like modules) are pickled by reference as opposed to attempting to pickle the object itself. '''