Am Mittwoch, 2. Oktober 2013 15:53:31 UTC+2 schrieb Simon King: > > On 2013-10-02, Jeroen Demeyer wrote: > > Whatever you do, the end result should be that old pickles still > > unpickle correctly. > > That's why I ask how one can replace a class with custom __new__ by a > ClasscallMetaclass. > > It seems that the following works:
- Use the classcall metaclass for implementing the singleton behaviour. - Add a `RationalField.__new__` method, that tries to return the instance `sage.rings.rational_field.QQ` and returns a new instance if it does not succeed. The following happens: - `RationalField.__new__` (creating a new instance) and `RationalField.__init__` are called once during start of Sage (no surprise). - `RationalField()` uses the classcall, but does *not* use `__new__` or `__init__` again. In particular, we still see the speed-up I mentioned. - `unpickle_all()` succeeds. During unpickling, `RationalField.__new__` is called frequently (I guess these must be extremely old pickles), but surprisingly do no call `RationalField.__init__` again. This seems like a valid solution to me. Of course, the documentation of `__new__` should mention that unpickling old pickles is the only reason for its existence. 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/groups/opt_out.