Hello Peter,

* Peter Bruin <pjbr...@gmail.com> [2014-05-13 07:05:43 -0700]:
> 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.
I agree. We probably want to be able to unpickle these old dictionaries.
Btw. you can not use an override to change the unpickling of dicts.
> Do we have to create special hashable subclasses of 
> previously-hashable-but-now-unhashable types?
That could be an option. It is not pretty but I don't see a better
solution. We would have subclasses of all unhashable types which are 
hashable and print some deprecation warning if their __hash__ is called.
If unhashable p-adics and hashable p-adics mix in a @cached_method
probably strange things will happen but at least we printed a warning
and told the user how to "upgrade" the old p-adics.
I'll try to implement something along these lines in #11895.

Thanks for the input,

julian

Attachment: pgpjnNwm871aS.pgp
Description: PGP signature

Reply via email to