The problems arising on #15149 arise from the fact that if objects occur as 
keys in dictionaries, then their hashes might be required prior to 
`setstate` being called on them during unpickling. If we trace where the 
failing `hash` comes from, we find it's

CategoryObject.__hash__(self):
        if self._hash_value == -1:
            self._hash_value = hash(repr(self))
        return self._hash_value

so in a way, it's CategoryObject that breaks the unpickling: If 
CategoryObject introduces a custom hash, it should also ensure that (at 
least by default), pickling ensures that it gets unpacked appropriately and 
is usable prior to __setstate__, a requirement that may seem a little 
surprising at first. Of course, CategoryObject has no idea what's required 
to compute repr(self), but if it would do something like:

def __reduce__(self):
    return _CategoryObjectReconstructor, 
(type(self),self.hash()),self.__dict__

def _CategoryObjectReconstructor(T,hashval):
    v = CategoryObject.__new__(T)
    v._hash_value = hashval
    return v

we'd at least recover "hash" (and I think it's safe to assume that 
repr(loads(dumps(obj))) == repr(obj), so we'd get the same result).

-- 
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/groups/opt_out.

Reply via email to