[Python-checkins] python/nondist/sandbox/datetime
obj_delta.c,1.9,1.10
Tim Peters
tim.one@comcast.net
Mon, 02 Dec 2002 13:10:56 -0500
[Guido]
> Try defining __reduce__.
OK ... but no joy:
# XXX Pickling fails in the C implementation.
# XXX timedelta has a __reduce__ method, which returns, e.g.,
# XXX
# XXX (<type 'timedelta'>, (), (1, 0, 0))
# XXX
# XXX but pickle then complains
# XXX
# XXX PicklingError: Can't pickle <type 'timedelta'>:
# XXX it's not found as __builtin__.timedelta
In one way that's not a mystery:
>>> timedelta.__module__
'__builtin__'
>>> timedelta.__name__
'timedelta'
>>>
OK, if I change the name of the type to "_datetime.timedelta", pickling
completes, but on unpicking a new error pops up:
UnpicklingError: <type '_datetime.timedelta'> is not safe for
unpickling
Arghghghgh ... OK, if I also give the type dict a __safe_for_unpickling__
attr, I guess it works.