Hi all! On 4 Jun., 08:14, Florent Hivert <florent.hiv...@univ-rouen.fr> wrote: > > If we should indeed prefer M.list() over list(M), perhaps we should > > provide a list method on SageObject that just returns list(self)? That > > way objects are OK if they just provide .iter(), but if producing a > > list efficiently is desirable for that object, the .list method can be > > overridden. > > Please don't ! At least not in SageObject. Rationale: most of object who have > a .list() method are actually Parent. In several categories, a proper .list() > method is defined. Since category are after concrete class in the mro, adding > .list() to SageObject will completely prevent defining it in categories. Here > is a proposition of solution: Put you object in the correct category which > define .list().
Why not providing a default implementation of list() as a parent method of the category of Sets (or perhaps even the category of Objects)? Then, the only thing that the user has to do is provide his/her parent with any category, what (s)he is supposed to do anyway. If it is in the category of Objects, then actually nothing is left to do for the user - at least the default implementation would always be there, because every parent is in the category of Objects. The default implementation could indirectly rely on an __iter__ method, but in addition it could test if the object is infinite, raise an error if it is, and try the best it can do if it is not clear whether the object is infinite. Something like this: def list(self): try: Fin = self.is_finite() except (AttributeError, NotImplementedError): Fin = True if Fin==False: raise TypeError, "This parent is infinite, we can not provide the list of its elements" return list(self) Then, it can be easily overridden by something more specific in an appropriate sub-category, and if the user does not know about categories it could also be overridden directly on class level. Cheers, Simon -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org