Hi Julian,

OK, I see the problem.  It seems that it is not unique to DirichletGroup, 
but is more general:

sage: class pAdicNumber(object): pass
sage: d = { pAdicNumber(): 0 }
sage: s = dumps(d)
sage: pAdicNumber.__hash__ = None
sage: loads(s)
...
TypeError: unhashable type: 'pAdicNumber'

For all we know, old pickles everywhere (e.g. on people's computers, not in 
the pickle jar) may contain dictionaries where p-adic numbers are used as 
keys.  What to do about this?  It sounds a bit drastic to generally change 
unpickling of dictionaries so that keys whose type is unhashable are 
silently dropped.  Do we have to create special hashable subclasses of 
previously-hashable-but-now-unhashable types?

Peter


Op dinsdag 13 mei 2014 12:46:56 UTC+1 schreef Julian Rüth:
>
> Thanks for your answers. 
>
> * Peter Bruin <pjb...@gmail.com <javascript:>> [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 sage-devel+...@googlegroups.com <javascript:>. 
> > To post to this group, send email to 
> > sage-...@googlegroups.com<javascript:>. 
>
> > Visit this group at http://groups.google.com/group/sage-devel. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to