Hi Nicolas, On 2014-05-01, Nicolas M. Thiery <nicolas.thi...@u-psud.fr> wrote: > Analysis: the __setstate__ method of ParentWithGens does not store the > category whenever _element_constructor is not implemented.
Funny. > Some approaches to fix this include: > > - Use UniqueRepresentation for permutation groups. > (with the side effect of them being pickled by construction). This would only fix this particular case. > - Implement a __reduce__ method to pickle by construction. This would mean to store the input parameters somewhere, which is likely to create new memory leaks. > - Implement an _element_constructor. Why isn't there, anyway? > - ... > > What's the best approach? Probably "...". What is the rationale for not storing the category when _element_constructor is not implemented? What has one to do with the other? I guess the underlying technical detail is that we have a Cython classes with cdef attributes (such as ._category or ._parent), and then derive a Python class from it. The Python class would by default way of pickling ignore anything that is not in __dict__. Hence, it would ignore ._category resp. ._parent. So, it may seem that we need a default __reduce__ method to deal with the cdef attributes. In the case of sage.categories.map.Map, we have these _extra_slots and _update_slots method that are supposed to be implemented in order to make some default __copy__ (or __reduce__) method work. I guess in principle this approach would work for ParentWithGens as well. But I am not so sure if this approach is nice. After all, how will you make people become aware that one needs not to implement __reduce__ but _update_slots and _extra_slots for pickling? Over several years (!), many maps could not be pickled, because no _update/extra_slots was implemented. Maps are fine now, by #14711, but how will you avoid similar things to happen again when providing a default __reduce__ that relies on custom methods that most Sage developers have never heard of? This may be related with Nathann's complaint about __mul__ relying on _mul_, _rmul_ and _lmul_. Best regards, Simon -- 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.