Thanks for your answers.

* Peter Bruin <[email protected]> [2014-05-13 01:23:56 -0700]:

> Here is my solution to a similar problem in #15158:
> 
> def __setstate__(self, state):
The problem is that __setstate__ never gets called because the error
happens earlier, during the unpickling of state.
In other words, if I change DirichletGroup to

sage: class DirichletGroup(object):
....:     def __setstate__(self, state):
....:         assert(False) # I never get here

then the assertion is not triggered by loads(s).

julian

> 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.

Attachment: pgpFAtdO_YJTN.pgp
Description: PGP signature

Reply via email to