You need to define a new __setstate__ method that allows for the old and
new way of doing things. Something like:
if isinstance(state, dict): # for old pickles from Partition_class
self._set_parent(_Partitions)
self.__dict__ = state
else:
self._set_parent(state[0])
self.__dict__ = state[1]
On Tuesday, 13 May 2014 12:16:28 UTC+10, Julian Rüth wrote:
>
> Hello sage-devel,
>
> at #11895 I'm trying to make p-adic numbers unhashable. This works
> nicely except for one pickle from the pickle jar that I can't seem to
> fix.
>
> The problem is that DirichletGroup_class used to have a dict which uses
> p-adic numbers as keys. That dict used to be a cache which is not used
> anymore, so dropping it would be no problem. However, I can only drop it
> after the dict has been unpickled. But this fails since the unhashable
> p-adic numbers can not be used as keys anymore.
>
> Here is a minimal example to illustrate the problem:
>
> sage: class DirichletGroup(object): pass
> sage: class pAdicNumber(object): pass # the old hashable p-adic number
> sage:
> sage: G = DirichletGroup()
> sage: G._cache = { pAdicNumber() : 0 }
> sage: s = dumps(G)
> sage:
> sage: class pAdicNumber(object):
> ....: __hash__ = None # now p-adics are not hashable anymore
> ....:
> sage: loads(s)
> TypeError: unhashable type: 'pAdicNumber'
>
> Any ideas how I could influence the unpickling so that the string s can
> be unpickled with the _cache dropped in this example?
>
> Thanks,
>
> julian
>
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.