Here is my solution to a similar problem in #15158:
def __setstate__(self, state):
"""
Needed to unpickle old Spec objects.
The name-mangled attribute ``__R`` used to be in a class
called ``Spec``; we have to translate this mangled name.
TESTS::
sage: S = Spec(QQ)
sage: loads(dumps(S))
Spectrum of Rational Field
"""
if '_Spec__R' in state:
state['_AffineScheme__R'] = state.pop('_Spec__R')
super(AffineScheme, self).__setstate__(state)
Op dinsdag 13 mei 2014 03:16:28 UTC+1 schreef Julian Rüth:
>
> 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.