On Saturday, September 7, 2013 8:01:20 PM UTC+1, Nils Bruin wrote: > C=[GraphNode() for i in range(4)] > for c in C: > c.neighbours.extend([b for b in C if b is not c]) >
I agree that you can't use the "object id as unique identifier" pattern. AFAIK the graph theory code in Sage does not work like that, but uses integers to enumerate nodes. If you really want unique GraphNodes then the "proper Sage" way of writing it is using UniqueRepresentation and, therefore, give it some constructor argument that uniquely identifies the node. In fact, we could still preserve uniqueness in circular references as long as there is no __reduce__ loop involved. The problem with __reduce__ is that it runs code, and running code on incomplete objects leads to unexpected results. Whereas it is safe to stick your hand into the object internals and just change the __dict__ of all instances until they are back to the original state. Actually, this is not quite true as Simon noted, unpickling of dictionaries still calls __hash__ on the keys. But close enough. First of all, I think we should never pickle cached data. Its just needless complexity, and non-doctestable surprises where pickle-ability now depends on which computations you did before pickling. Plus, switching it off is probably the only thing that we can change quickly. Second, __reduce__ loops should be forbidden. Technically, they already are since Python does not support them. But unfortunately you just get corrupt pickles instead of a clear error at pickling time. Ideally, we'd have a doctest that ensures that there is no reduce loop in any Sage object. As a corollary, any __reduce__ method should always just pickle the absolute minimum to recreate the object. -- 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.